Unmount USB drives from a script in macOS

I have a number of external drives hanging off my laptop, but sometimes I want to disconnect them. I used to go into Finder and click the eject button but I have five drives now so that’s getting unwieldy.

There are a few different ways of doing this. I wrote a small BASH script based on information here.

I created a shell script on my Desktop, added the following, changing DRIVE to the volume path for each of my external drives:

osascript -e ‘do shell script “diskutil unmountDisk /Volumes/DRIVE”‘

After creating that script I made it executable with chmod +x and as I use iTerm2 as a terminal I associated .sh files with that (Finder, right click on script, Get Info->Open With).
Every time I double click the script a new tab opens in iTerm2 and I see the progress of the unmount commands!

Leave a Reply

%d bloggers like this:

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close