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.
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)'
In Terminal try:
umount -a
(All the filesystems described via getfsent(3) are unmounted.)
umount -A
(All the currently mounted filesystems except the root unmounted.)
Fore more information see man umount
.
Seems like you can also use this:
diskutil unmountDisk /dev/disk*
Didn't test it, though. If it doesn't work, try to use "unmount" instead of "unmountDisk".
Oh, I also found the eject
argument (instead of unmountDisk
). That might also be of interest.
diskutil eject /dev/*
seems what you are looking for (see comments).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With