AddThis Social Bookmark Button

Print

Hit-and-Run: Launching AppleScripts with Keyboard Shortcuts

by Jochen Wolters
06/08/2007

AppleScript automation is one of OS X's most useful features. It lets you automate common, repetitive tasks so you can spend your time on more important things. Some AppleScripts would be even more useful, and their usage more seamless, if you could launch them by just hitting a key combination. And you can. Here are three ways to assign a keyboard shortcut to an AppleScript.

A Bit of Context: iTunes Fadeout Script

As context for this article, I'll be using David Battino's useful (at least to aesthetically demanding music fans) iTunes Fadeout Script as an example: when iTunes is playing, the script smoothly fades the volume to zero before pausing the track; if iTunes is paused, it will smoothly fade in, starting where it left off. (I prefer the version of the script that does not require any user intervention. It's the bottommost source code in David's article.)

Launch the Script Editor from the /Applications/AppleScript folder, create a new document window, copy and paste the source code from David's blog post into this window, and save the file to the Desktop as "Pause iTunes."

Where to Store AppleScript Files on Your Mac

Before we actually assign a keyboard shortcut to this script, let's examine the four key locations on your Mac in which an AppleScript file should be stored. When and where you can access a script is determined by where you store the respective file. The scripts in three of these four locations are listed in the OS X Script Menu. To display this menu on the righthand side of the menu bar, launch the AppleScript Utility from the /Applications/AppleScript folder, and check the "Show Script Menu in menu bar" option. Figure 1 shows what you will see in that menu:

figure
Figure 1. OS X's Script Menu. Note the submenu that provides easy access to the three scripts folders.

And this is where the scripts listed in the Script Menu are taken from:

Library Scripts folder

/Library/Scripts/

The scripts inside this folder are accessible from all user accounts on the machine and are always listed in the Scripts Menu if you check the "Show Library scripts" option in AppleScript Utility. On a newly installed Mac, the library scripts are comprised of a number of more or less useful example scripts provided by Apple.

User Scripts folder

<your user folder>/Users/Library/

The scripts in this folder are only accessible when you are logged in as the respective user, but they are always available in the scripts menu, regardless of which application is currently frontmost.

Pages: 1, 2, 3, 4, 5

Next Pagearrow