I wrote a few tips for Chris Seibold‘s book, Mac Hacks: Tips & Tools for unlocking the power of OS X, and he gave me the green light to publish this one. If you:
- keep your impressively oversized iTunes library on an external hard drive
- are tired of quitting iTunes and manually ejecting your media drive (this goes especially for my fellow MacBook users)
This Automator tip is for you and, if you’re the cliff notes type, so is the download cheat sheet I created below. While we’re at it, Chris’s entire book of Mac Hacks is up your alley too, you should grab a copy.
[button color=”white” background=”green” size=”large” src=”http://finerthings.in/wp-content/uploads/2013/07/Eject-iTunes.zip”]Download Automator action – Eject iTunes[/button] [divider]
I’m going to venture a guess that most of you reading this use a MacBook as your primary Mac, and that your iTunes library has grown too big for its britches. You moved it to an external drive, didn’t you? And now you wish there were an easy way to quit iTunes and eject your drive at the same time to bring back that good ol’ fashioned “grab and go” feeling that got you using a MacBook to begin with, right? I think I can help.
With a little Automator and a dash of Terminal, you can create a utility that does exactly what I described, which can make your portable life just a little easier. You can put this utility in your Dock or give it a shortcut with a productivity utility like Alfred or LaunchBar—whatever lets you work the fastest. Let’s get started.
Step 1: Quit iTunes
The first thing you want your Automator utility to do is quit iTunes for you, and you just need one action for that. Here’s how to set that up:
- Launch Automator
- In the “Choose a type for your document” window, pick ￼”￼Application” and then click Choose
- On the left side of the Automator window, click the Library heading (if it’s not already selected)
- In the next column to the right, scroll down in the list of actions until you find Quit Application. Double-click it to add it as the first step of the Automator utility you’re creating
- In the rightmost pane of the Automator window, in the pull-down menu in the Quit Application action you just added, select iTunes
You’ve now created a utility that quits iTunes. So far, so good.
Step 2: Tell Automator to Wait
I don’t know about you, but iTunes sometimes takes a couple seconds to quit, even on my powerful, maxed out, SSD-slinging Retina MacBook Pro. Maybe it’s tidying up some changes I made to the library database, or maybe it’s just checking to see if it left the oven on. Whatever the reason, I’ve been using a Mac long enough to know that if an app is depending on an external drive, you should wait for the app to truly quit before you cut it off from that drive. So let’s add a slight pause to your action:
- In the list of actions in the second-to-left column in Automator, find the Pause action and double-click it to add it to your utility
- In the rightmost pane, specify how many seconds you want Automator to wait. I recommend a pause of three seconds, but this is really up to you. Enter your best guess as to how much time iTunes needs to do its thing
Step 3: Eject Your Drive
Now comes that dash of Terminal I mentioned. Automator strangely doesn’t have any kind of “eject external stuff” action, so we need to get slightly messy with a single-line Terminal command:
- In Automator’s list of actions, find Run Shell Script and double-click it to add it to your utility. In the main Automator pane, and make sure the Shell menu in the upper-left corner of that action is set to “/bin/bash”
- In the action’s text box, delete any existing text and then add this line of code:
hdiutil eject /Volumes/the name of your external iTunes drive
You’ll need to substitute the name of your external iTunes drive into the end of that command. For example, my command is:
hdiutil eject /Volumes/iTunes
Because my iTunes drive’s name is simply “iTunes.” If your drive’s name has more than one word, you’ll need to add a slash to the end of each word, like this:
hdiutil eject /Volumes/My Hard Drive
Step 4: Save Your Utility
You’re all set. In fact, if your external drive is connected right now and iTunes is running, try clicking the big Run button in the upper-right corner of Automator’s window. If everything’s set up right, iTunes should quit and your drive will be ejected.
Now it’s time to save your Automator utility as an application that you can fit into your workflow (you can also download and edit my ZIP file cheat sheet). Go to File→Save, give it a relevant name like “Eject iTunes,” pick a convenient location to save it, and be sure the File Format menu is set to Application. When everything looks good, click Save.
Congratulations! To the chagrin of many a music startup and competitor, you just created an, ahem, iTunes killer. Now it’s time to actually use it.
Step 5: Make Your Utility Useful
You could place your new iTunes killer in the Applications folder and then drag it to your Dock for easy access. Or, if you’re really feeling lazy, you could just put it on the desktop and launch it from there. But there are fairly easy ways to assign this utility a shortcut so it’s just a keystroke away.
In System Preferences→Keyboard→Keyboard Shortcuts, you can create a new Application Shortcut by choosing Application Shortcuts in the left-hand list and then clicking the + button. Then browse to your new utility and assign it a shortcut that will make OS X launch your utility and run that series of commands no matter what you’re doing or what app you’re using.
Or, if you use one of the Mac’s popular productivity utilities like Alfred, LaunchBar, or Quicksilver, they each have a variation on the theme of assigning a shortcut to any file or folder. In my favorite, Alfred, you do it by going to Preferences→Hotkeys. You can also tinker with Alfred’s Extensions panel, where you can create bundles of multiple apps to open or close with a single shortcut.
However you decide to work your new iTunes killer into your workflow, I hope it saves you at least a little time fumbling around with quitting the app and then ejecting the drive it depends on. After all, those little bits of time do add up.