is there a way to eject all external hard drives from the command line? (OS X)

dan picture dan · Jan 12, 2010 · Viewed 11.9k times · Source

Is there a way to eject all the mounted hard drive volumes on an OS X computer from the command line? Applescript is OK if I can wrap that in a shell script.

Answer

naich picture naich · Aug 28, 2011

There is another elegant way to unmount all external hard drives without knowing the exact names:

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'

To ignore network mounts and optical disks, use:

osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true and local volume is true and free space is not equal to 0)'