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 4 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

Write a comment: