I'm looking for a way to get the .dmg path of a mounted disk image with just its mount point.
I want to write a "simple" Finder service that ejects the disk image and trashes the accompanying .dmg. The ejecting is trivial, but I'm at a loss as to how to figure out the path of the .dmg, given just the mount point.
diskutil doesn't seem to know or isn't saying.
It's for a script, so AppleScript- or shell-based suggestions are preferred.
Use
hdiutil info
to get the information about currently mounted images. Then usehdiutil detach /Mount/Point
to dismount all file systems, and detach the image.You'll need to parse the output from
hdiutil info
to find the right image-path if multiple images are mounted. It will probably be more robust to use the plist output formathdiutil info -plist
and run that into, say, a python script with plistlib or an AppleScript using theProperty List Suite
fromSystem Events
.Here's a quick and dirty python script to give you an idea. It's easy to explore options using the python interpreter: