Fixing Mac OS X’s Preview: Home and End keys that work all the time with Keyboard Maestro

Posted by Pierre Igot in: Macintosh
June 10th, 2010 • 2:56 pm

When it comes to viewing PDF files, I much prefer Mac OS X’s own Preview application to Adobe’s own monstrosity known as Adobe Reader (to say nothing of the beyond-atrocious Acrobat Pro). Preview launches quickly, it offers high-quality font smoothing, and the latest version (5.0.x, in Snow Leopard) has an improved tool for selecting and copying text.

That does not mean that Preview is perfect, far from it. It suffers from a number of frustrating limitations and inconsistencies. For example, the selection tool still includes punctuation marks (commas, colons, etc.) when selecting entire words. And, on my machine at least, Preview 5.0.x has a tendency to crash on a regular basis.

One of the more long-standing issues I have with Preview, however, is with the way it handles focus and keyboard shortcuts. When you view a PDF document, you usually have a sidebar that contains either a table of contents or thumbnails of the document’s pages, for quick navigation.

The problem is that the behaviour of Preview’s keyboard shortcuts, including common ones such as Home and End and Page Up and Page Down, varies depending on whether the focus is currently on the document itself in the main area of the window or on the sidebar.

And that’s particularly problematic in light of the fact that the visual clues for the current focus are very minimal. There’s no blue halo around the sidebar or the main area. The only way you can tell that the focus is on the sidebar and not on the main area is the fact that the caption of the currently selected thumbnail is highlighted in the foreground selection colour and not in the background grey used when a selection is in the background.

Here’s a selected thumbnail when the sidebar is in the foreground:

Thumbnail in FG

And here’s the same selected thumbnail when the sidebar is in the background:

Thumbnail in BG

(Don’t ask me why the highlighting for the frame around the thumbnail is still in the foreground selection colour.)

The situation is similar when the sidebar contains a TOC.

In the foreground, you get this:

TOC in FG

And in the background, you get this:

TOC in BG

If you haven’t selected anything in the sidebar, or if the visible portion of what’s in the sidebar does not include your current selection (because you’ve scrolled beyond it), you are out of luck, because there are really no visual clues indicating whether the focus is on the sidebar or the main window area.

And unfortunately, this is important, because the meaning of the Home, End, Page Up and Page Down shortcuts changes depending on what the focus is on.

If the focus is on the sidebar, Home, End, Page Up and Page Down apply to the sidebar and not to the pages of the PDF document itself.

And if you do a search with the toolbar search field, for some reason the Page Up and Page Down shortcuts work as expected (i.e. they scroll through the found pages of the document in the main window area), but not the Home and End shortcuts, which do… nothing.

It’s all very frustrating, so today I decided to make myself a couple of Keyboard Maestro macros that would work all the time, regardless of what the current focus is (on the sidebar, on the main area, or on the search field).

More specifically, I created a “Home” macro which:

  1. simulates a mouse click at (200,100) from the front window’s top left corner
  2. simulates the Home keystroke

The first step ensures that the focus is on the main area of the window. And then the second step just does what the Home key is supposed to do.

I assigned the command-Home shortcut to it, et voilà. Now I have an easy-to-remember shortcut for going all the way back to the beginning of a PDF that works all the time, regardless of whether the focus is on the sidebar, the search field or the main area.

I did the same with a command-End shortcut for the corresponding macro to go to the end of the PDF. And while I was at it, I also created “proper” macros for going up and down one page and assigned the command-Page Up and command-Page Down shortcuts to them.

To me, these shortcuts are appropriate because they don’t have any special function in Preview (as opposed to a word processor, where they would be expected to move the insertion point as well). Either they don’t do anything at all, or they do the same thing as the key without the Command modifier. And they are easy to remember. And, most important, unlike the regular shortcuts, they work all the time.


Comments are closed.