Add a keyboard shortcut to any Services menu item

Apr 08, '03 10:13:00AM

Contributed by: bluehz

You can easily add a keyboard shortcut to any item in the Services menu. The problem is finding a shortcut that is not already being used by something in the System or one of the applications you use. To add a keyboard shortcut to an item in the services menu, follow these steps...

Read the rest of the article for the step by step instructions.

[robg adds: Bandwidth warning: I added three images to this tutorial to make it clearer, so the remainder of this article is about 50k in size. Also, we ran something similar on removing shortcut keys from services, but this tutorial goes into much greater detail...]

To add a keyboard shortcut to an item in the services menu:

  1. Determine the item you want to add a shortcut for and then determine if the shortcut you want to use is already being used elsewhere.

  2. Locate the application that contains the shortcut you want to add too. Control-click on application icon and select "Show Package Contents".

  3. Navigate to the Contents directory and open the file Info.plist with a text editor, or preferably the PropertlyList Editor.

    If using PropertyList Editor:

    Click the triangle next to Root and then scroll down and locate the NSServices entry. Inside that entry you should see each item that appears in the services menu for that application, identifed by a number (0 = first item, 1 = second item, etc.). Locate the one for which you want to add a keyboard shortcut. Click the expansion triangle to reveal the listing underneath it. It should contain something like this:

    You will be adding a new child under the numeric heading for the service item you want to modify. Make sure the numeric heading (in example above it is 0) is highlighted and click the Add Child button at the top of the window. Select the new entry that appears and enter NSKeyEquivalent in the first field and select Dictionary in the second field. So now it should look like this:

    Highlight the "NSKeyEquivalent" item and click the "Add Child" button again to add a new entry under it (note: the disclosure triangle must be pointing down, otherwise you'll see "New Sibling" instead of "Add Child"). Select the new entry and enter "default" in the first field and select "String" in the second field. Now enter a single letter or character in the third field. This will be your new keyboard shortcut along with command+shift. So if you enter "Z" in the third field your keyboard shortcut for that menu item is command+shift+Z. You should now have something like this:

    Save the Info.plist and close.

    If using a Text Editor robg adds: Note that the screenshots above are from TextEdit's services menu; the following example is from BBEdit, so they don't agree with each other -- that's my fault when creating the screenshots

    Search for "NSServices" in the file. Locate the item you want to modify and change as shown below (read above for details as necessary).

    Before

    <dict>
      <key>NSMenuItem</key>
        <dict>
          <key>default</key>
          <string>BBEdit/Open Selection</string>
        </dict>
      <key>NSMessage</key>
        <string>openSelection</string>
      <key>NSPortName</key>
        <string>BBEdit</string>
      <key>NSSendTypes</key>
        <array>
          <string>NSStringPboardType</string>
          <string>TEXT</string>
          <string>utxt</string>
      </array>
    
    After
    <dict>
      <key>NSKeyEquivalent</key>      <==== add
        <dict>                        <==== add
          <key>default</key>          <==== add
          <string>B</string>          <==== add
        </dict>                       <==== add
      <key>NSMenuItem</key>
        <dict>
          <key>default</key>
          <string>BBEdit/Open Selection</string>
        </dict>
      <key>NSMessage</key>
        <string>openSelection</string>
      <key>NSPortName</key>
        <string>BBEdit</string>
      <key>NSSendTypes</key>
        <array>
          <string>NSStringPboardType</string>
          <string>TEXT</string>
          <string>utxt</string>
      </array>
    
    Save the Info.plist and close.

  4. You will need to logout and log back in again to see your changes in the Services menu.
Notes

Comments (14)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20030406004351266