X

How to set up an Eject All hot key in OS X

OS X requires that you manually eject all drives before disconnecting them, which can be a bit of a burden if you have multiple drives attached. Here's a way to simplify things a little.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
3 min read

If you have a MacBook system that you regularly use at a desk such as in an office work space, then you may have a number of peripheral storage devices set up to manage backups and work-specific data, whether attached directly to the system or through a Thunderbolt, FireWire, or USB docking device. These can be convenient when you need them, but quite the opposite when you're packing up to depart.

The main reason for this is OS X's requirement that you manually unmount each drive that's attached to the system by either dragging it to the trash, clicking the eject button next to it in the Finder sidebar, or using the Eject function in the system or contextual menus. If you have multiple drives attached, you will need to systematically eject each one or chance interrupting communication with the drive, which may result in data loss.

While this isn't as much of an issue with desktop systems, with a laptop it is often easy to close the lid and pull the plugs to quickly be on your way, only to wake the system to a number of warnings about not having properly ejected your disks.

EjectAll service work flow in Automator
Set up this Automator work flow as a systemwide service, which can then be bound to a hot key for quick access to unmount any attached drive (click for larger view). Screenshot by Topher Kessler/CNET

Luckily, with the use of Terminal commands and Apple's Automator utility you can set up a hot key to quickly unmount all drives from your system, which should speed up your escape.

To do this, first open the Automator utility in the OS X Applications folder, and then follow this procedure:

  1. Create a new Service work flow
  2. Set the service to receive "No Input" but work in "All Applications"
  3. Locate and drag the Run Shell Script action to the work flow window
  4. Change the default "cat" command to the following two commands (the first removes all "ejectable" media like optical disks, and the second unmounts all drives except for those in use, such as the boot drive):

    diskutil eject /Volumes/*
    diskutil unmountDisk /Volumes/*

  5. Save the service with an appropriate name (such as EjectAll)

At this point you can test the work flow to see if it ejects your disks for you (it should). Since the work flow is a service that is available for all applications, it should now be available in the Services submenu of the application menu (next to the Apple menu) for the foremost program. Additionally, you can set a custom hot key to invoke this service at any time. To do this, go to the Keyboard system preferences and select the Services section in the Keyboard Shortcuts tab. In here, locate the new service by the name you gave it (it should be listed under General) and click the "Add shortcut" button to assign a hot-key sequence to it.

With this done, you can now invoke the hot-key sequence or select the service from the application menu to quickly unmount and eject all attached drives and have your system ready to go.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.