So, I decided to write a script that would unmount image disks. More complicated than I thought at first.
FIRST, run this …
on run set imageInfo to (do shell script "hdiutil info -plist ") tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo}) -- set newFilePath to ((path to desktop) as text) & "hdiutil-info.plist" tell application "System Events" make new property list item with properties {kind:record, value:InfoRecord} make new property list file with properties {contents:the result, name:newFilePath} end tell end run
This will create the .plist file on your desktop. Open it with Xcode so you can refer to it in the next script.
Second, run this script …
on run set imageInfo to (do shell script "hdiutil info -plist ") tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo}) -- set mountPointList to {} set imagesList to images of InfoRecord repeat with imageItem in imagesList set entitiesList to |system-entities| of imageItem repeat with entityItem in entitiesList try |mount-point| of entityItem set mountPointList to mountPointList & {the result} end try end repeat end repeat log mountPointList beep end run
You can verify that it is correctly identifying the disks. And you can compare the script with the contents of the .plist file in order to understand the script.
Now, all you have to do is replace log mountPointList with script which tells the Finder to eject the disks. Here's a completed script that will eject every image disk.
on run set imageInfo to (do shell script "hdiutil info -plist ") tell application "System Events" to set InfoRecord to value of (make property list item with properties {text:imageInfo}) -- set mountPointList to {} set imagesList to images of InfoRecord repeat with imageItem in imagesList set entitiesList to |system-entities| of imageItem repeat with entityItem in entitiesList try |mount-point| of entityItem set mountPointList to mountPointList & {the result} end try end repeat end repeat
repeat with mountPoint in mountPointList -- very slooooow (POSIX file mountPoint) as alias tell application "Finder" to eject the result end repeat beep end run
|