Keyboard Shortcuts for AppleScripts: An iTunes Power Tip for Mac Users

Note: The behaviors described below are from Mac OS X 10.4.10. Previous versions of the OS might not behave as described. YMMV.

Keyboard shortcuts are the life-blood of the power user. Casual users know of the basic ones: Command-Q to quit, Command-W to close a window, Command-F to find, etc, but the power users have them all memorized for every program they use. For them, actions that would take 3-5 seconds of arduous mouse work can be accomplished in as little as half a second of keyboarding. That’s up to a 10x increase in productivity! Heck, many individuals, myself included, can go for minutes without even touching the mouse.

But even the most vaunted power user might not know this trick.

Mac OS X (both Panther and Tiger) has a little-promoted feature that lets you customize some of those keyboard shortcuts for menu items. Even some global commands can be changed to suit your tastes. Don’t like Command-P to Print? Change it. You can even make it an F-Key and return some functionality to your keyboard’s top row. In some cases, you can give shortcuts to menu items that don’t have one.

There are some caveats however:

  • When entering your new keyboard shortcut, you must make sure you type the Menu Item exactly as it appears in the Menu. Same spelling, capitalization and punctuation. Many menu commands end with an ellipsis, which you can type by pressing Option-; (semi-colon).
  • Also, if you choose a key combo that already exists, in most cases, the new one will replace the old one, leaving the original without a shortcut. Some programs will assign the duplicate shortcut, but it just won’t work.
  • Finally, there are apps that will not be affected by the changes you make. Photoshop, for one, uses its own internal shortcut customization scheme and won’t recognize anything you change in System Preferences.

So, having said all that, let’s apply it to iTunes.

The Macintosh version of iTunes, as you may well know, can extend its capabilities via AppleScripts, those little bundles of code that help with repetitive tasks, make organizing easier and add new features. A new Scripts Menu will appear in the Menu Bar when AppleScripts are installed script menu. If you’re reading an article on how to add a keyboard shortcut to them, you probably already know this. The beauty is that the system treats the Scripts Menu just like any other and you can add a keyboard shortcut to any script you have installed.

Identify Scripts

The Scripts Menu before

Start by opening iTunes. Click on the Scripts Menu and determine which scripts you want to add shortcuts to. Note their names as they appear in the drop-down. For this example, I’m selecting a Script called Embed Artwork. It copies album art downloaded from the iTunes Store into the individual music files; iTunes doesn’t do that by default, so I end up using it pretty frequently. I’ll also do Quick Convert, since I often use it to convert podcasts into audiobooks for faster listening.

Apply the Shortcuts

adding keyboard shortcuts to itunes

Open System Preferences. Select Keyboard & Mouse, then Keyboard Shortcuts. Click the + (plus) sign in the lower left, then select iTunes from the Applications pop-up. In the Menu Title field, enter the name of the script. In the Keyboard Shortcut field, press the key combo you wish to use. For Embed Artwork, I’m choosing Command-F1, Quick Convert gets Command-F2. A modifier key is required in iTunes. Stand-alone F-Keys, for whatever reason, will show up in the menu but they won’t do anything when pressed. When you’re satisfied, press Add to save.

Relaunch iTunes

The Scripts Menu after editing keyboard shortcuts

iTunes loads the keyboard shortcuts when it is launched, so quit and reopen it. When you click the Scripts Menu, you’ll see your new shortcuts displayed next to your script titles.

It is important to remember that configuring keyboard shortcuts, in general, is an inexact process. If something doesn’t work, find an alternative. I know I would love to use those F-Keys in iTunes. but for now, I’ll have to settle for the workaround. Still, these added functions will be a boon to anyone’s productivity.

One thought on “Keyboard Shortcuts for AppleScripts: An iTunes Power Tip for Mac Users

  1. Yeah, but it would be much nicer if I could just add something to the script file name to do this.. You could do this with old (pre-OSX) menus – ie have a menu item that was “Add Item/A” I believe would put a command-A on it. Or maybe it was a backslash – I forget..

    Anyway, apparently in Mail (at least some version of Mail), you *can* do this, as outlined in the hint here:

    You just name the script something like “script-name___ctl-cmd-p.scpt” would assign Control-Command-P to it, and so on.

    Why this behavior is not system-wide with Applescript menus? Who knows? (I assume all AS menus are basically done the same way – that *is* why OSX programmatically is so object-oriented right?)

    Maybe it doesn’t work in Tiger 10.4.11 even in Mail.

    BTW I think Apple should just scrap the whole Keyboard shortcuts dialog for making shortcuts, and just buy MenuMaster from Unsanity. Having all the shortcuts in one place (as with the Keyboard pref pane) *is* a good idea. But MenuMaster’s method for adding them is much nicer and probably more intuitive (if a user knows about it at all). And it saves you the question of having to remember the EXACT way something is spelled, and what if there are two items with the same name? Or two items with the same name in different submenus?

    Apple might even extend the current MenuMaster code in a way that it you hit a key that was assigned to another menu item, it would open other menu with the conflicting item in yellow (the title of the menu, the outline of the menu itself, and then a box around the item itself). Unsanity could I guess theoretically do that – but it would require hacking a LOT of the menu classes – and might only work with Cocoa-based menus. Apple *has* the code, so.. It’s easier. You could continue with whatever procedure you used to “commit” a key change, in which case the other key on the conflicting item would disappear, or you could choose something else, in which case the auto-open-yellow-outline-menu would disappear..

    Even nicer – if you *did* go ahead and assign a key that had a conflict and resulted in another item key being removed – the Keyboard prefpane could note ” conflicts with [submenu->]*

    How to deal with items that change dynamically might be tricky as there’s no way for the system to automatically determine this behavior. In Sound Study, there is an item “Show Levels Window” that changes to “Hide Levels Window”. I have both assigned to . Works fine – it puts in whichever item is in the menus.

    How you work this with a MenuMaster type interface isn’t quite clear. Does it assign the command to both items (ie to the number of the NSMenuItem in the NSMenu – or whatever it is in the Foundation layer class underneath the Cocoa), or just to one of the (in which case it must check the item text whenever a call to change a menu item’s text is made)


Leave a Reply

Your email address will not be published. Required fields are marked *