Open iTunes with option key pressed?

Is there a way for Keyboard Maestro to open iTunes and hold Option at the same time so that it brings up the box to switch libraries?

I am using KM 6.4.7 on Mac 10.9.5.

Thanks. :slight_smile:

@Emm -

There is good news and there is bad news about doing that.

You can find both answers immediately, by using search in the upper right corner of this screen:


Were you able to accomplish this? I have 3 iTunes libraries that I frequently go between. Ideally, I’d like to set up hotkey to open each specific library without having to go through the library menu.


This is a very simple macro to option-open iTunes. If it's already running the macro will quit it first:

[test] Option-Open iTunes.kmmacros (4.7 KB)

The rest (opening a specific library) is a thing of GUI scripting, since I don't think there is direct AppleScript access to that.

Thanks for this but I’m just getting iTunes opening to the current library. It’s not bringing up the library menu. Any ideas?

Have you tried it several times? Sometimes the Option key doesn’t seem to get pressed, I don’t know why. Mostly (9 out of 10) it works here, but this may depend on the actual system and hardware config.

Play around with some slight Pause actions before/after/inbetween the modifier key actions.


If it doesn’t work well enough for you, I’ve seen a nice idea on Stackoverflow, which is based on changing iTunes’ library prefs on the fly.

It works fine in the Terminal and if you want we can build a macro around it.

OK, here is a macro that does the trick without GUI scripting:

Open iTunes with a Specific Library.kmmacros (8.6 KB)

When you launch the macro it will…

  1. Quit iTunes in case it is running
  2. Prompt you for the desired library
  3. Change iTunes library pref via a shell command
  4. Launch iTunes

Unfortunately iTunes does not store the library path as a human-readable POSIX path but as Alias data.

So, before running the macro the first time you have to gather that data. This is a one-time thing and it is simple:

1) Launch iTunes with your first (non-default) library.
2) Quit iTunes.
3) Run this command in the Terminal:

echo -n $(defaults read 'alis:1:iTunes Library Location') | pbcopy

This will copy the Alias data of the current iTunes library to the clipboard.

4) Paste the clipboard into the first green Variable value field ("iTunesLib1"). It should look similar as shown in the screenshot.

Repeat the steps for your other iTunes libraries, filling up the other two variables ("iTunesLib2" and "iTunesLib3"). You don't have to do that for the library at the default location (~/Music/iTunes).

  • The macro has slots for three libraries plus the default library location. Add or remove slots to your liking.
  • Rename the library names in the Prompt action to your liking. (But keep the Variable part of the names intact.)


The macro does a minor sanity check for the pasted data before changing iTunes’ prefs. If it finds anything that does not start with "<" and end with ">" it will set the library location to the default by removing the location entry from the prefs.

1 Like


Thanks very much.

Worked great once I overcame a few brain cramps. Also, had trouble with the macro halting on time out due to it taking a long time for the previous open iTunes to save the library, so I had to disable timeouts for the All Conditions Met actions.

Don’t know how many use multiple libraries, but that’s a good macro to post (if it isn’t already).


I have established the timeout because otherwise I (sometimes) ended up with two running instances of the macro when there were problems with quitting/starting iTunes.

In any case it’s not a good idea to restart iTunes with another library while it is still busy with the currently open library. I got several iTunes crashes doing so.

So I recommend to not open iTunes with different libraries in very short order. Give it some time (10 to 20 seconds).

Please read (again) the instructions for the macro in my post above.

As said the macro has slots (room) for 3 different library locations, not counting the default library location.

You see the three green actions in the macro? These are the 3 variables (“iTunesLib1”, “iTunesLib2”, “iTunesLib3”) whose task is to hold the location data for the libraries.

Just use the Terminal command from above as described to get the location data for each library, and paste that data into the value field of one of the green Variable actions.

Do not change the name of the variables! But of course you can change the displayed names in the User Prompt action (“John”, “Jim”, “Jack”), after the double underscore.

If you need more than 3 library locations (that is, more than 4 if we count the default location), then just…

  1. duplicate (⌘D) one of the green Variable actions and name the Variable “iTunesLib4”
  2. Execute the shell script for that library and paste the obtained data to the new action
  3. Add an entry to the User Prompt with this pattern: %Variable%iTunesLib3%__John where “John” is the freely choosable displayed name. The entries have to be separated by a pipe (vertical line) character “|”.


To reply to any of my posts please click the “Reply” link at the bottom of that post. Otherwise I will not get notified via mail.


Understand about adding additional libraries. I was just suggesting that it would be a good macro to post.

Ah, sorry, I completely misunderstood. (I interpreted your sentence as “don’t know how to use many multiple libraries”, because otherwise I couldn’t make any sense out of it. My bad.)

Happy to hear that it works for you.

Well, the macro is effectively posted here. However, a forum admin (for example @JMichaelTX) could maybe assign the thread (or the latest posts starting with post #4) to the Macro Library category.