I want to eject all hard drives with a command on the Terminal instead of going to the Finder and pressing eject on each drive. How can I do it?
How to eject all drives from the command-line
command lineejectterminal
Related Question
- MacOS – The disk “Vol” couldn’t be ejected because “Terminal” is using it
- How to open a new Terminal window ssh’ed to another machine from the command line
- Rewrite ‘eject remove’ command
- MacOS – menu bar tool which will let me eject external drives easily
- Unable to eject disk images or drives in High Sierra
- Eject on menu bar shows “No Drives” even though an external drive is connected
- How to safely eject a volume when the icon has disappeared
Best Answer
You can use the in-built AppleScript solution, as mentioned in this thread and this page, by adding this to
~/.bash_profile
:This will require you giving permission to Terminal to control Finder, or you will get this error:
If you want a pure
bash
solution, here is a function that you can call withejectall
. If you renamed your startup disk or have different Time Machine backups, you may need to edit the condition that filters out the drives.Both methods will also work for CDs.