|
Related Reading
Modding Mac OS X |
Editor's note: Make repetitive tasks simpler and maximize ergonomic efficiency with this excerpted chapter from Erica Sadun's Modding Mac OS X. This comprehensive chapter covers everything from the philosophy of keyboard shortcuts to step-by-step instructions to a look at speakable items, complete with shortcut management tips and screenshots. Neat, concise, and easy-to-use, this excerpt helps you add, remove, and change keyboard shortcuts to meet your personal computing needs. Keep your hands on the keyboard and give that mouse a rest.
The Keyboard Shortcuts preferences pane lets you associate a custom shortcut for any menu item in any or all of the applications on your Mac. This feature lets you add a new menu shortcut or override the original keyboard shortcut for a menu item. You can also add shortcuts to individual applications or globally to all applications, as described in the following section.
All application shortcuts in this chapter are case-sensitive. Always take care to match the case, spelling, spacing, and punctuation when defining a shortcut. Non-English-language readers: please note that you will need to adapt the instructions in this chapter to match the exact text on your system. For example, French-language readers do not use Secure Empty Trash. The menu item title is Vider la Corberille en mode sécurisé.
|
TOOLS YOU NEED
For working through the examples in this section, you’ll need the
following applications:
|
Apple’s infinitely hackable Calculator (/Applications) offers no keyboard shortcut for turning speech recognition on or off. As Figure 8-5 shows, the two-item Speech menu has no keyboard shortcuts at all. In the following steps, you’ll use the Keyboard Shortcuts preferences to add a shortcut for the Speak Total menu option.
![]() Figure 8-5. The default look for Calculator's Speech menu. |
![]() Figure 8-6. Clicking the + button opens this dialog on top of the Keyboard Shortcuts pane. |
![]() Figure 8-7. Specifying the Application, Menu Title (really, the menu item), and Keyboard Shortcut. |
defaults utility, which runs from the command
line. Start by launching the Terminal application (/Applications/Utilities).Enter defaults read com.apple.calculator. This command requests
a list of the defaults (preferences) from the com.apple.calculator property
list file, which stores all the preferences used by Calculator. The new
keyboard shortcut appears, associated with the NSUserKeyEquivalents
key (highlighted in bold in the output).
Figure 8-8. The modified Speech menu. Speak Total now has a keyboard shortcut.
$ defaults read com.apple.calculator
{
NSUserKeyEquivalents = {“Speak Total” = “~T”; };
"NSWindow Frame Calc_History_Window" = "419 344283 0 0 1024
746
";
"NSWindow Frame Calc_Main_Window" = "113 459283 0 0 1024 746
";
PaperTapeVisibleDefaultsKey = 0;
PrecisionDefaultsKey = 13;
SpeaksButtonPressedDefaultsKey = 0;
SpeaksTotalDefaultsKey = 0;
ViewDefaultsKey = Basic;
"dv com.apple.soundmgr._DV Sound Output Settings" = <7d000000
>;
}
Any item that returns from the defaults command will also
appear
in the actual preferences plist file associated with that domain. When
opened in TextEdit, you’ll find the same updated preference. To see
them, launch TextEdit and open ~/Library/Preferences/com.apple.calculator.
plist.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC “-//Apple Computer//DTD PLIST 1.0//EN”
“http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0”>
<dict>
<key>NSUserKeyEquivalents</key>
<dict>
<key>Speak Total</key>
<string>~T</string>
</dict>
<key>NSWindow Frame Calc_History_Window</key>
<string>419 344283 0 0 1024 746 </string>
<key>NSWindow Frame Calc_Main_Window</key>
<string>113 459283 0 0 1024 746 </string>
<key>PaperTapeVisibleDefaultsKey</key>
<false/>
<key>PrecisionDefaultsKey</key>
<integer>13</integer>
<key>SpeaksButtonPressedDefaultsKey</key>
<false/>
<key>SpeaksTotalDefaultsKey</key>
<false/>
<key>ViewDefaultsKey</key>
<string>Basic</string>
<key>dv com.apple.soundmgr._DV Sound Output Settings</key>
<data>
fQAAAA==
</data>
</dict>
</plist>|
Editing Application Shortcuts
Use the following tricks to edit the application shortcuts in your Keyboard Shortcuts preferences pane:
|
|
As you may have noticed, some Mac OS X applications use an ellipsis (…) as part of their menu items. When you see an ellipsis tacked onto a menu item, it means that the item will open up another window in which you’ll have more work to do. Many of Calculator’s menus, for example, contain items that end with an ellipsis. Unfortunately, there are two ways that programmers can add an ellipsis to a menu item, and you have to take this into account when you define your keyboard shortcuts. Some programmers actually type in three dots, a triple repetition of the period (.) character. Other programmers use the Unicode ellipsis character, which is a single character that adds all three dots (...). It can be very hard to differentiate these visually, unless you know what you’re looking for.
Curiously enough (and rather conveniently, from the viewpoint of this technical author), Calculator 3.1 uses both approaches. If you launch Calculator and carefully look at the File and Convert menus, you’ll discover that the File menu uses three dots and the Convert menu uses an ellipsis, as shown in Figure 8-9. The dots are slightly heavier and spaced a little further apart than the ellipsis character. Convert menu uses the ellipsis character.
In the following steps, you’ll use the Keyboard Shortcuts preferences pane to set shortcuts for both types of ellipsis.
WARNINGYou should never modify an application that’s currently running. The application won’t recognize the changes until it relaunches, and it may overwrite the changes you’ve made by exporting its current set of preferences when the application quits.

Figure 8-10. Use the International preferences Input Menu pane to provide
quick access to the Character Palette.
Click on the Add button, as shown in Figure 8-11. The new shortcut appears in Application Keyboard Shortcuts under Calculator.

Figure 8-11. Adding a shortcut using three period characters.
Mac OS X’s Character Palette lets you add the full range of Unicode characters to your applications and documents. The Character Palette is indispensable when it comes to working with foreign languages and special fonts. To learn more, search for “typing special characters and symbols” in Mac Help. Choose Help -> Mac Help (Command-?) from the Finder.
Figure 8-12. The ellipsis character
appears in the Punctuation set of the
Roman character palette. |
Click the Add button. The new shortcut joins the list, as shown in Figure 8-13.

Figure 8-13. The shortcuts defined by these steps.
Enter defaults read com.apple.calculator | grep UserKey. This
command searches for Calculator’s keyboard shortcuts:
$ defaults read com.apple.calculator | grep UserKey
NSUserKeyEquivalents = {"Area\\U2026" = "~A"; "Page Setup..."
= "~P"; "Speak Total" = "~T"; };

Figure 8-14. The updated Calculator replaces the File -> Save Tape As
menu shortcut with Shift-Command-S and adds Option-A as the Convert -> Area shortcut.
As you can see, the Page Setup shortcut simply uses the three typed dots. In contrast, the Area shortcut uses the Unicode ellipsis character U2026. This code is found on the second page of the Unicode standard code charts (http://www.unicode.org/charts/charindex2.html; the list starts at http://www.unicode.org/charts/ charindex.html), as shown in Figure 8-15. Unicode escape sequences allow you to add and edit exotic equivalents via your keyboard without using Mac OS X’s Character Palette.

Figure 8-15. The Unicode site allows you
to look up the Unicode equivalent for
many common symbols.
You won’t see this spelled-out Unicode shortcut if you open Calculator’s plist file (~/Library/ Preferences/com.apple.calculator.plist) in TextEdit or Property List Editor, because TextEdit can read and display Unicode natively. As Figure 8-16 shows, the ellipsis looks like an ellipsis in TextEdit.

Figure 8-16. TextEdit is fully Unicode
compliant and displays special symbols
directly.
WARNINGYou might be tempted to define a keyboard shortcut in System Preferences and then modify the shortcut by editing the resulting application preferences file. Do NOT. System Preferences will overwrite your changes every time you log in, reverting the shortcuts to the ones stored in its database.
Keyboard shortcuts can apply to individual applications or across the board
to every application on the system. When you choose a particular application,
as you did in the previous example, the shortcut affects only the domain that
you specify; you selected Calculator, and the shortcuts were then mapped to
that application only. The Keyboard Shortcut preferences also allow you to define
shortcuts for All Applications. When you do this, the keyboard shortcut is added
to the global domain (also called the NSGlobalDomain), defining
a shortcut that affects all matching menu items in all applications. The following
example shows you how to create a global shortcut.
Figure 8-17. Adding a global
keyboard shortcut.
|
defaults
command. This command reads all the preferences from the global domain and
searches for any keys that include UserKey.
$ defaults read NSGlobalDomain | grep UserKey
NSUserKeyEquivalents = {Clear = "^X"; };
Instead of typing outNSGlobalDomain, you can use thedefaults -gflag; for example, try usingdefaults read -g | grep UserKey.
Return to MacDevCenter.com.
Copyright © 2009 O'Reilly Media, Inc.