Use hdiutil info
to get the information about currently mounted images. Then
use hdiutil 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 format hdiutil info -plist
and run that into, say, a python script with plistlib or an AppleScript using the Property List Suite
from System Events
.
Here's a quick and dirty python script to give you an idea. It's easy to explore options using the python interpreter:
>>> import plistlib
>>> from subprocess import Popen, PIPE
>>> output = Popen(["hdiutil", "info", "-plist"], stdout=PIPE).communicate()[0]
>>> pl = plistlib.readPlistFromString(output)
>>> for image in pl['images']:
... for se in image['system-entities']:
... if se.get('mount-point') == '/Volumes/blah':
... print image['image-path']
/Path/To/blah.dmg