2 years ago
Saturday, November 17, 2007
Hunt and Peck: An Investigation and Proposal for Better Custom Keyboard Shortcut Management in OS X
The short story: The interface and functionality of custom keyboard shortcuts in OS X is awkward and unreliable. There are two possible direct reasons for this — Apple’s development priorities and non-standard application resource organization — and any number of underlying causes. I propose a solution.
This is the very long story. I am primarily a Camino user, but like anyone developing for the Web on a Mac, I usually have Firefox and Safari open at the same time too. My keyboard shortcut habits were formed in Firefox, though, and it’s too late to switch from ⌘+K for the search box, and ⌘+⌥+← and ⌘+⌥+→ for tab navigation. Having acquired a new laptop recently, I was reminded just how awful the process for setting up custom keyboard shortcuts is in Mac OS X.
Of Mysteries and Ellipses
If you’ve set custom keyboard shortcuts before, this interface will look familiar. In fact, it remains unchanged since OS X 10.3.

The problems here are manifold.
First, you have to find the exact name of the menu option you want to access. This requires switching back and forth between an open application and the Keyboard & Mouse preference pane, with nowhere but your mind (or a piece of paper, or a Sticky, but come on) to store the title of the menu command, which is itself potentially buried several levels below the top-level menu options.

This is further complicated by the fact that keyboard shortcuts don’t take effect until you’ve closed the very application you were getting the menu option from. (It doesn’t say that anywhere in the interface itself; you just have to come to that conclusion by trial and error or Help when it doesn’t work immediately.) Even if you remember whether, say, that app capitalizes “to” or “from,” there’s no way to assure you’re typing the right thing. The best example of this is the ellipses, used to denote a menu option that triggers further action in a dialog box.
Can you spot the difference?

Here you go:

Apple specifies in the HIG section on Style that menu options requiring further input or confirmation should feature genuine ellipses:
Important: Be sure to create the ellipsis character using the key combination Option-; (Option-semicolon). This ensures that an assistive application can provide the correct interpretation of the character to a disabled user. If you use 3 period characters to simulate an ellipsis, many assistive applications will be unable to make sense of them. Also, 3 period characters and an ellipsis do not look the same because the periods are spaced differently than the points of an ellipsis.
But just because something’s in the HIG doesn’t mean developers will abide. Firefox is a great example. A sample custom shortcut:

And sure enough, it matches up:

This is problematic.
Of course, it’s known that third parties aren’t the only ones who don’t adhere to the HIG. The “Search Google…” menu option in Safari, pictured above, raises a few tangential questions: Does it even deserve an ellipsis? It just quietly puts focus on the Google search bar, which I didn’t notice until I’d tried selecting it a few times. The neglected HIG doesn’t account for menu items that do things like that. Hidden as it is, this menu option in Safari almost seems to exist for the sake of being custom-shortcut’d.
Assuming you do get the menu command title right, there’s no guarantee that setting the custom shortcut function is actually going to work. I spent twenty minutes trying to set keyboard shortcuts in Safari and wondering why they would show up sometimes but not others. In the end I had too many screenshots to deal with. I think this one, taken after I attempted to create a shortcut for “Private Browsing,” will suffice:

Some sort of type-ahead mechanism that would fetch the right menu command for you would solve this problem, but that brings us to why this functionality isn’t already built-in.
Not a Key Feature
Obviously, making the custom keyboard shortcuts interface eminently usable is not a priority for Apple. For the most part, only a minority of users actually know and use keyboard shortcuts. Of those I bet a significant number desire at least some level of customization, but at the end of the day, it’s not a feature that moves units. It’s understandable, then, that it hasn’t been prioritized.
I initially suspected another reason: that improving the process would actually be quite difficult. Here’s why.
While it’s possible to get a complete list of the menu options of any running application with Applescript, it would be best if the preference pane didn’t need to run the application just to get the menus. So instead, providing a searchable list of default menu options for an application (dynamic things like the bookmarks and history in a web browser should be ignored) would require a registered list thereof for every available application. But do these even exist? If so, where?
Turns out they do. But “where” is exactly the problem.
In many applications (both Apple’s and those by third parties), the default menus are found in the MainMenu.nib interface file of an application. See for yourself: ‘Show Package Contents’ on the Safari application, navigate down through Contents › Resources › English.lproj › MainMenu.nib. If you’ve got Developer Tools installed, you should be able to open that file. You’ll see in the MainMenu.nib window something called “MainMenu,” an object of the NSMenu class, which manages an application’s menus.

Theoretically, a list of menu options should be obtainable from this .nib file. Unfortunately, it’s not always in the same place. For Calculator, it’s in Calculator.nib instead of MainMenu.nib. With DVD Player, it’s in MenuBar.nib. For Mail, I couldn’t even find it. So the preference pane wouldn’t know where to look without loading the application to tell it. Right?
Wrong! The location of the MainMenu-containing interface file is specified in the NSMainNibFile property of a given application, listed in the Info.plist directly inside the Contents folder of every application. Knowing this, it’s easy, for instance, to find the appropriate .nib for Mail, MailViewer:

Peachy Key’n
I’ve leave the implementation for another day, but all of the pieces are already there. The Keyboard & Mouse preference pane can already tell when an application disallows keyboard shortcuts:

And it knows that because — and here’s the kicker — it checks the Info.plist file! Check it out:

If a property exists to disallow keyboard shortcut customization, we can only assume that the list of available applications listed in the Keyboard & Mouse prefence pane is drawn from a cached list of applications whose menu commands can be edited. It wouldn’t be too far a stretch to get Keyboard & Mouse to then cache a list of the available commands from the MainMenu object in the appropriate .nib for each safe application.
The interface for finding the right menu command should work just like the new Help menu in Leopard. The screen would dim and a facsimile of the selected application’s default menus would appear. Start typing a command, and the close matches would be pointed out visually with the bobber. Once you’d selected a command (by searching or by manually navigating through the menus with the mouse), the command would fly from the menubar into the preference pane, where you could set a keyboard shortcut for it which would then be checked against existing shortcuts.
A warning dialog indicating that changes to existing keyboard shortcuts wouldn’t take place until the application was restarted would then appear, offering, like Software Update, to quit said application immediately or postpone quitting.
It can be done. It should be done. The ball’s in your court, Apple.
See Also
John Gruber’s article Losers, Weepers speaks to the problems of the OS X custom keyboard shortcut feature, and was written way back in 2003 when the feature first appeared. (There are a lot of similarities there, but it’s worse that the problems haven’t been addressed in four years than me not remembering John’s original post.) He mentions a key problems not mentioned or addressed here but just as vital — the lack of conflict management.
2 Comments






screen but at the keyboard, or at another window, or even at notes on their desk while typing. In this case, it’s dangerous to just stop accepting input. They may continue typing without actually accomplishing anything and not realize it until they’ve wasted time typing something they may not remember.




