Assign Shortcut Keys to Script Menu AppleScripts
The macOS has the ability to assign menu shortcut keys in pretty much every application, including AppleScripts listed in the Script Menu of the Media apps. Here's how to do it.
(Hey! If you don't want to do-it-yourself, FastScripts from Red Sweater Software provides the ability to quickly and simply add and manage AppleScript keyboard shortcuts. I highly recommend it.)
Set Up Your System Preferences
Note: This will only work with scripts that have been installed in an app's "Scripts" folder such that a script appears in the app's Script menu.
Quit the app. You can't attach a keyboard shortcut to an application if it is running.
Open your System Preferences and click on "Keyboard". Click on the "Shortcuts" tab. Select "App Shortcuts" from the list on the left.
Click on the "+" button. In the Application pop-up of the sheet that appears, select the app you the shortcut is to appear in. Next, enter the name of the AppleScript to which you want to assign a keyboard shortcut exactly as it appears in the Script Menu. In the Keyboard Shortcut field press the combination of keys you want to use for the shortcut.
Setting the shortcuts for the Pretend We Played This script in
System Preferences > Keyboard > Shortcuts > App Shortcuts.
The key combination I pressed is Shift-Command-X.
Click the "Add" button. Close System Preferences.
The next time you start the app, look in its Script Menu. The shortcut you assigned will be displayed adjacent to the name of the Script you assigned it to, just like a real menu shortcut! That's because it is a real menu shortcut.
For more details, search your Mac Help for "Setting custom keyboard shortcuts for applications".
OF COURSE, this isn't just for assigning shortcuts to items in the Script menu. You can also assign keyboard shortcuts for menu commands that don't already have a shortcut, such as "Check for Available Downloads...", "Export Library...", "Check for Updates...", and so on. (And in this blog post, I describe a cool trick to unambiguously assign shortcuts to menu items in sub-menus.)
If you assign a keyboard shortcut which iTunes is already using you may get mixed results. For example, I assigned Shift-Command-Nwhich is iTunes' "New Playlist from Selection" shortcutto a script and the script fired (the script actually does the same thing as "New Playlist from Selection" but asks for a new playlist name first). But it wouldn't let me assign Command-A, the universal "Select All" shortcut. It also knows what keys you have assigned already, and it will warn you if you try to enter a duplicate shortcut.
As far as using the F keys: I could only get combinations that included Command to work. No problem, though. There are still hundreds of key combinations available.
Check out the Missing Menu Commands page for some mini-scripts that work great with shortcuts.
Here are some suggested scripts to which you may want to assign a shortcut:
- Play Random Album v3.1
[ For iTunes ] Creates and plays playlist using tracks from album chosen at random - Search-Replace Tag Text v5.5
[ For iTunes ] Perform search-and-replace on text in your choice of tags - Remove n Characters From Front or Back v5.10
[ For iTunes ] Delete characters from the beginning or ending of selected tracks' name, artist, album, comments, composer, or show tags - Player Position to Start or Stop v2.0
[ For iTunes ] Set current track's start or stop time to current player position - Reset Bookmarks to Start v2.0
[ For iTunes ] Reset selected tracks' bookmark position to their Start Time - Whack Current Track v2.0
[ For iTunes ] Deletes the current track from all playlists and moves to Trash - Just Play This One v3.0
[ For iTunes ] Play the selected track and stop - Have a Quick Look v1.0
[ For iTunes ] View selected tracks, PDFs in QuickLook windows