Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Create keyboard shortcuts for stubborn Cocoa apps Apps
If you're missing a keyboard shortcut for a menu item in one of your apps, and the Keyboard Shortcuts tab of the Keyboard & Mouse preference pane doesn't get you anywhere, you can use Interface Builder to assign one. It's easy.

As an example, I've added a shortcut to the View » Sort Subscriptions By » Unread Count menu item in NetNewsWire, since I like to have my feeds sorted by the number of unread posts while I'm reading them. I got fed up with always having to choose it from its buried sub-menu via the mouse.

You need Interface Builder for this hint, and it's part of Xcode (formerly Developer Tools) that you can download for free from Apple after you've registered as an ADC member, which is also free. This hint involves digging into the application's contents, so if you're afraid you might break something, it's probably best to make a backup of the application. However, any change made with IB is easily undone.

Note: this hint only works with (Cocoa) applications whose interface is built using the standard manner of creating nib files. If this is not the case, or if the app developer has used tricks to keep people from opening their nib files (as some do), you are out of luck.

Here we go:
  1. Make sure the app you want to work on is not running. Locate the app bundle (the normal program icon; in my example:, then Control-click on the app and pick Show Package Contents from the pop-up menu. A new window will open with one folder named Contents.
  2. Go to the Resources folder (inside Contents), and then find the folder for the interface language in which you are using the application. In my example, this folder is English.lproj.
  3. Inside the language folder, find the main nib file, usually called MainMenu.nib, and double-click it to open it in Interface Builder.
  4. In Interface Builder, there will be a central window that contains all the items that are part of this nib file. There should be one named MainMeu. This contains the definition of the application's -- you guessed it -- main menu. Double-click it.
  5. You will be presented with the menu, attached to a special window. Now navigate to the menu item for which you want to define a keyboard shortcut. In my example, it's the Unread Count sub-menu item of the Sort Subscriptions By menu item of the View menu. This menu item should be selected and highlighted.
  6. Open Interface Builder's Inspector window by choosing Inspector from the Tools menu (in Interface Builder; not in the menu that you are about to edit!) or pressing Command-Shift-I. The first pane of the Inspector, Attributes, should be displayed. If it isn't, press Command-1 or click on the first pane at the top of the Inspector. The Inspector window's title should read Menu Item Attributes.
  7. At the bottom of that pane, you will find a setting labeled Key Equiv. This is for setting the key equivalent -- or shortcut -- for this menu item. Just click in the box next to the label and press the shortcut that you want. Be careful not to choose one that is already used! In my example, I used Command-S (short for sort). This is usually the shortcut for saving, but NetNewsWire has no such menu command, and thus no such keyboard shortcut in use, so I'm okay to use it.
  8. Verify that the menu item actually has the keyboard shortcut that you want. It should be displayed on the right next to the menu item, as you're used to it. OK? Then save the nib file, and we're done!
You can now quit Interface Builder, and launch the edited app. If everything went smoothly, you should now be able to invoke your previously shortcut-less menu item using the new shortcut.

Some notes:
  • You may not find the menu item in question in the MainMenu item inside the MainMenu.nib file. Some nib files have more than one menu, and the menu in question may also be in another nib file than the main one. In that case, just try looking inside the other nib files, and make sure you've checked all the menus in each of the nib files. You can always tell the menus from the other nib contents (windows etc.) by their rather menu-ish looking icons.
  • If you're using an older version of Interface Builder, you might not be able to open some of the nib files, because they are in a newer format that your version of IB can't open. Try updating your Xcode to the latest version. However, you might be out of luck if you're running OS 10.4 Tiger or earlier, as the most recent versions of Xcode only run on Leopard (10.5).
  • Even if you have the latest Interface Builder, you might still not be able to open some or even all of the nib files. Some developers don't want people to look inside their nib files and use various tricks to prevent it. Also, the nib(s) may use custom Interface Builder controls that may prevent you from opening the file or may cause problems editing or later saving that nib file.
  • If there is no Show Package Contents menu item when you Control-click the app icon, or if there is no Resources folder inside the Contents folder, or no language folder inside the Resources folder, and there are no nib files anywhere to be found, then the app is probably not a (standard) Cocoa app, and/or the developers have used various techniques to hide their stuff from you. In these cases, I'm afraid, you're out of luck.
[robg adds: I'm not sure why using the standard Keyboard Shortcuts tab doesn't work for this menu item in NNW, but I tested it, and it doesn't.]
  • Currently 1.80 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (5 votes cast)

Create keyboard shortcuts for stubborn Cocoa apps | 8 comments | Create New Account
Click here to return to the 'Create keyboard shortcuts for stubborn Cocoa apps' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: earthsaver on Jan 27, '09 09:35:21AM

I, too, have had occasional problems with Keyboard Shortcuts prefs not behaving kindly. Perhaps this solution gets easier after you do it once. But for the simpler solution, I recommend Unsanity's MenuMaster.

- Ben Rosenthal
PBG4 1.25 - Leopard

[ Reply to This | # ]
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: bcometa on Jan 27, '09 09:40:34AM

great hint! never knew about interface builder.

it's easier than it seems after reading the instructions (but the instructions are very helpful). just double click the .nib file for the menu you want to add the shortcut to, and set the shortcut in interface builder.

thanks for sharing!!

[ Reply to This | # ]
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: hamarkus on Jan 27, '09 03:07:49PM

I've tried in past unsuccessfully to add a keyboard shortcut to 'Create AAC Version' in iTunes. The shortcut shows up in the menu but does not work, ie, using it does nothing. I might give this hint to try for this.

[ Reply to This | # ]
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: asmeurer on Jan 28, '09 03:57:53PM
There is an easier way!
Authored by: fcanas on Feb 15, '09 12:49:51PM

It's a lot easier than this. You don't need interface builder. You don't need to backup the application. You don't even need to quit the application or restart it for the changes to take effect!

1) Open the "Keyboard & Mouse" system preference pane

2) Go to the "Keyboard Shortcuts" tab

3) Click on the little "+" sign below the list of shortcuts

4) Select the application via drop-down menu

5) Enter the exact name of the menu item you want a short cut to

6) Assign your new keyboard shortcut. -- and done!

[ Reply to This | # ]
There is an easier way!
Authored by: NachoJ on May 10, '10 04:09:57PM


[ Reply to This | # ]
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: jocamero on Feb 15, '09 03:42:57PM
Anyone have any luck doing this with RealVNC Enterprise? (viewer doesn't require a key)

Upon opening Interface Builder it appears most menu items (that I want to assign a keyboard value) are already assigned to the appropriate value and enabled.

i.e. Command - Q is set to Quit and enabled, yet when you open the application, the keyboard shortcut doesn't work, and the keyboard shortcuts no longer appear in the application's drop down menus. Previous builds of RealVNC had this functionality.

Specifically I'd like Command - Q to quit the app and Commmand - N to open a new connection window. Any ideas?

[ Reply to This | # ]
Create keyboard shortcuts for stubborn Cocoa apps
Authored by: palahala on Feb 15, '09 04:30:07PM

> RealVNC Enterprise? (viewer doesn't require a key)

A bit off-topic and just for the record: the sole fact that the viewer does not need a key to run, does not imply that it is freeware. As far as I know, the Mac OS X VNC Viewer may only be used to connect to VNC Enterprise Server installations, which do need a license.

Note that Leopard has a VNC compatible client built-in (Finder, Cmd-K, type an address starting with vnc://). Other free alternatives would be Chicken of the VNC, JollysFastVNC, and probably some others. RealVNC also offers a cross-platform Java viewer.

[ Reply to This | # ]