This article originally appeared in TidBITS on 2009-09-08 at 3:37 p.m.
The permanent URL for this article is: http://tidbits.com/article/10545
Include images: Off

Hack Microsoft Word's Page Up/Page Down Keys

by Pete Resnick

Microsoft Word has always screwed up the Page Up, Page Down, Home, and End keys on the Mac. I believe - and am willing to quote chapter and verse [1] from the Apple Human Interface Guidelines to support my belief - that they should, respectively, scroll up one screen, scroll down one screen, scroll to the top of the document, and scroll to the bottom of the document. And they should do all this without moving the bloody insertion point!

Before Visual Basic for Applications went away, I wrote some macros that did this and reassigned the key commands. In Word 2008, however, there's no VBA. So I finally figured out four one-line AppleScript scripts that bring back my desired scrolling behavior.

Copy each of these lines to a new document in AppleScript Editor (Snow Leopard) or Script Editor (Leopard) and save them in ~/Documents/Microsoft User Data/Word Script Menu Items, naming them, respectively, "Page Up", "Page Down", "Home", and "End" (the exact names are important for later on). Files in this folder show up in the scripts menu in Word, which is the first step.

tell application "Microsoft Word" to large scroll active pane of active window up 1

tell application "Microsoft Word" to large scroll active pane of active window down 1

tell application "Microsoft Word" to set vertical percent scrolled of active pane of active window to 0

tell application "Microsoft Word" to set vertical percent scrolled of active pane of active window to 100

Then comes the problem of how to assign these scripts to the associated keys. You can't use the Tools > Customize Keyboard command to assign keys to AppleScripts in Word. Microsoft's advice is to put some magic key-equivalent crud at the end of the script's file name (like "\smV" for Shift-Command-V, which I use for Paste Plain). But there's nothing to type for the Page Up, Page Down, Home, and End keys. And, unfortunately, there's no way to add Page Up, Page Down, Home, and End to any key in the Keyboard Shortcuts view of the Keyboard pane of System Preferences.

If you had a macro program like Keyboard Maestro, QuicKeys, or iKey, you could bind the scripts to the appropriate keys within Word. But what if you don't have such a program? Once again, "defaults write" saves the day. In Terminal, first check to see if Word is listed in the results of this command (be sure to copy and paste each of these commands as a single line):

defaults read com.apple.universalaccess com.apple.custommenu.apps

If you don't see "com.microsoft.Word" in there (you probably won't), add it with this command:

defaults write com.apple.universalaccess com.apple.custommenu.apps -array-add "com.microsoft.Word"

Then, the magic happens with this last command:

defaults write com.microsoft.Word NSUserKeyEquivalents '{"Home" = "\UF729"; "End" = "\UF72B"; "Page Up" = "\UF72C"; "Page Down" = "\UF72D";}'

It's probably best to quit and relaunch Word if it was running, but after all this, you should have Page Up, Page Down, Home, and End keys that scroll the text in view as expected, but without moving the insertion point.

Should you want to reverse the effects of these commands, the easiest way is to (in Snow Leopard) go into the Keyboard Shortcuts view of the Keyboard pane of System Preferences, select Application Shortcuts in the left-hand list, select Microsoft Word in the right-hand list, and click the minus button. (In Leopard, you'd look in the Keyboard view of the Keyboard & Mouse preference pane, and scroll down to the bottom to find Microsoft Word in the list of Application Keyboard Shortcuts.)

[image link] [2]

[Pete Resnick used to be a Macintosh programmer, and ostensibly knows something about email and the Internet. Now his entire career is reduced to giving presentations and talking to lawyers, hence his constant use of Microsoft Word.]

[1]: http://developer.apple.com/mac/library/documentation/UserExperience/Conceptual/AppleHIGuidelines/XHIGUserInput/XHIGUserInput.html#//apple_ref/doc/uid/TP30000361-TPXREF52
[2]: http://www.tidbits.com/resources/2009-09/Word-in-Keyboard-Shortcuts.png