OSX AppleScript command line util to eject all removable disks

2009/05/26

On my MacBook pro, I’ve got 4 removable hard drives (2 physical in 2 partitions each) and a JungleDisk mount.

I found it painful to manually eject each individual drive in the finder so I threw together this quick AppleScript to eject all the disks.

tell application "Finder"
	eject (every disk)
end tell

Just open up /Applications/AppleScript/ScriptEditor.app and paste that in. Then choose “Save As” and pick “Application”. That will compile the script and create a .app file that you can click on to run, or you can put it in your path and execute it there.

I think the same kind of script could be created with the command line “diskutil eject” command, but this seemed cleaner as I wasn’t able to come up with a generic way to figure out which disks were “ejectable” and which weren’t. AppleScript is able to figure that all out for you.

There are 7 comments in this article:

  1. 2009/06/4scot nery say:

    Thank you thank you thank you.

  2. 2010/02/17Jake Walker say:

    This is just what I was looking for. Thank you so much.

  3. 2010/02/25Curtis Spencer say:

    Well done sir. Saves me a few clicks before I leave the house.

  4. 2010/03/4Richard M say:

    Perfect; thank you.

    Would you know how to make it pop up a “All disks ejected” message once the operation is complete? I guess you need some kind of wait loop that checks that all desks have successfully been ejected…?

    Richard

  5. 2011/05/15Apex say:

    Works perfect. Thanks!

  6. 2011/05/16Michael Wenyon say:

    This does not seem to work for internal disks in my Mac Pro. Is there a simple way to do this, too?

  7. 2011/05/16tednaleid say:

    @michael This is really only for disks that are labeled “ejectable” by the OS. Internal disks normally aren’t ones that you would want to eject so the applescript above doesn’t do that. If you’ve got some sort of hot swappable drives, you’ll probably want to dig into the `umount` command, which is something you could still script in applescript, though it’d need to be a little different (and probably executed with `sudo` privileges).

Write a comment: