Sunday, July 23, 2006

Adding a keyboard shortcut to an OS X Service

[I did this post to solve a problem, but it turned out there were far better solutions. So I cleaned it up a bit and moved it here, because the techniques may have other uses.]

Suppose you want to assign a shortut key to a Service item. For example, the OS X 10.3 and 10.4 -- "speech service". Select a word or phrase, choose 'Speak' and the machine speaks. Cool.

Here's how to do it.

This service is available in all Cocoa apps, such as Nisus Writer Express and Safari (but not Firefox -- it's not Cocoa ... yet). Alas, it's tedious to invoke. You have to select text, go to the menu item, etc.

But could I assign this service a shortcut? Google was again my best friend, it found Mac Modding Shortcuts, a tutorial on how to assign keyboard shortcuts to menu items (Cocoa apps only methinks). I didn't know if this would work for services, which are not really part of an application menu, but it does (with one glitch).

You can read the tutorial, or if you're brave you can find the OS X System Preferences, select Keyboard, then select Shortcuts then select Applications, add a shortcut as per the picture below. (You'll probably need the full tutorial really, this is kind of obscure. For example, you have to quite Safari before you do this assignment.) Note these shortcuts are user specific, they don't apply to all users on a machine.

The first time I did this I missed that the 'Menu Title' isn't a name I'm giving the shortcut, it's the EXACT verbiage used in the menu. I guess this utility uses a text matching rule to find what to invoke. I assigned Option-S to the shortcut. I did it only for Safari.

One bug is that it doesn't work the first time on you use it after launching Safari. You have to speak something using the menu method before the shortcut works. Tiger doesn't have this bug, but you still need to exit Safari before creating the shortcut.


  1. I know this is *insanely* much later to ask this, but did you ever find and fix the bug where you'd have to manually select the option in the menu first, before the hotkey would work?

    I have the the exact same problem with a shortcut in Safari, and I can't find any help anywhere...

    If you've had any movement on that, I'd appreciate any info you have :)

  2. Sorry, no f/u info. I long ago forgot about this feature and the bug -- even though I wrote the post!