Posts Tagged ‘AppleScript’

How to easily assign keyboard shortcuts to AppleScripts

Saturday, March 28th, 2015

AppleScriptThere is more than one way to assign a keyboard shortcut to an AppleScript file. The simple method I outline in this post does not require a third-party scripting utility or fussing with Automator. You accomplish this feat by using a specific set of characters in the filename of your script.

In researching the topic I found contradictory information on the Web. Many people claimed that this method once worked but stopped working around the time Snow Leopard was released. So it’s possible that Apple broke this capability in some versions of OS X but fixed it in subsequent releases. But that’s speculation; what I’m sure of is that it works fine in OS X Yosemite 10.10. (Please post in the comments if you know that this method works, or does not work, in other specific versions of OS X.)

You assign keyboard shortcuts to AppleScripts by using the backslash character (\) and a specific arrangement of a set of letters as part of the script’s filename. When appearing after a backslash, the letters correspond to these specific keys:

s = Shift
c = Control
m = Command
o = Option

Example AppleScript filenames and the keyboard shortcuts they assign:

script-name\smG.scpt = SHIFT-CMD-G
script-name\scG.scpt = SHIFT-CTRL-G
script-name\soG.scpt = SHIFT-OPTION-G
script-name\cmG.scpt = CTRL-CMD-G
script-name\coG.scpt = CTRL-OPTION-G
script-name\moG.scpt = CMD-OPTION-G

The letter G is an example that represents any letter, number and some other keys you might include as the trigger for the keyboard shortcut. It is the last character before the dot and file extension. It’s possible to assign key combinations that conflict with OS X system-wide and app-specific keyboard shortcuts. You need only check the app that will be active when you invoke the keyboard shortcut for potential conflicts.