In Mail: Can I set focus/detect if in Folder pane, MailList pane, on on Email and them Page Up/Down accordingly?

When I’m in the Mail app I want to be able to Page Up/Page Down, Cmd+Home/End in the Folder list pane, Mail list pane or in an email depending on which pane has the focus. (Or alternatively, maybe use 3 key sets, Ctrl+Page Up/Down, Alt+Page Up/Down and Cmd+Page Up/Down to set the focus to the correct pane and then send the correct key command to do that and a similar set for Ctrl+Home/End, Alt+Home/End, Cmd+Home/End.)

I know KM can tell which app it is in, but I can’t see anyway to know which sub-pane I’m in or how to set the focus to a particular (other than the inelegant kludge of moving the mouse X x Y pixels over, but that depends on me not resizing the target App (here Mail).

BTW, I’m look for a way to tell which sub-pane I’m in, almost as much as I want a way to do this, so I can use that ability elsewhere.



Hey Stuart,

This may work for you, although it only moves the focus to the mailbox list pane — nor is there any error-checking to make sure the pane is open — etc…

tell application "System Events"
  tell application process "Mail"
    set focused of outline 1 of scroll area 1 of splitter group 1 of window 1 to true
  end tell
end tell

I’ve tested only on 10.9.5, and Yosemite’s Mail may have different indices for its parts.

You can determine what pane you’re in with System Events, although working with SEV is complicated.

You can also brute-force the interface by using the search keyboard shortcut to enter the search field and then tabbing forward or backward.

And there’s another trick or two using keyboard shortcuts and AppleScript.


Thanks, but it didn’t in Yosemite. I’ve done a ton of programming on the Windows side using Visual Basic, so programming, per se, doesn’t phase me. Do you know of any reference site where I learn the syntax and which area is which?


Hey Stuart,

You can play with this script in the Applescript Editor (Script Editor on Yosemite) with the Event Log open, but it's pretty gnarly.

Probe Window with System (6.0 KB)


ui scripting reference

If you have installed Xcode then you'll have access to the Accessibility — it's not great, but it's better than nothing.

I bought UI Browser years ago to save my hair.

One of the better AppleScript books is:

Learn AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X

But there are only a few pages on GUI-Scripting.

If you really want to learn AppleScript you need at least one good book, and you need to hang out on and the Applescript Users List. (Archive)

There's a lot of stuff on StackExchange and other places too.