Emacs has a nice feature in the C-M-v keybind (scroll-other-window in Emacs Lisp), which causes the other window in a frame with two windows to scroll (I haven't tried it with more than two windows) without switching to the other window. Is there a way to get equivalent functionality with Mac OS X toplevel windows (i.e. non-Emacs windows)?

In particular I'm interested in scrolling Chrome and iTerm windows, but a more general solution would be great. I assume I would have to install a hotkey app of some sort, but I'm not averse to that.


I don't know any way to get the second frontmost application or window with AppleScript, apart from something like this:

delay 0.3 -- time to release modifier keys if the script is run with a shortcut
tell application "System Events"
    set p to process 1 where it is frontmost
    set visible of p to false
    delay 0.01
    key code 121 -- 121 = page down, 116 = page up
    set frontmost of p to true
end tell

It makes the hidden and activated windows flash though.

With browsers you could use window.scrollBy():

tell application "Safari" to tell document 1
    do JavaScript "window.scrollBy(0,(window.innerHeight-20))"
end tell

tell application "Google Chrome" to tell active tab of window 1
    execute javascript "window.scrollBy(0,(window.innerHeight-20))"
end tell

Another option would be to simulate pressing ⌃F4, page up or page down, and ⌃⇧F4 by for example using KeyRemap4MacBook:

<autogen>__KeyToKey__ KeyCode::CURSOR_UP, ModifierFlag::FN | ModifierFlag::CONTROL_L | ModifierFlag::NONE, KeyCode::F4, ModifierFlag::CONTROL_L, KeyCode::PAGEUP, KeyCode::F4, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L</autogen>
<autogen>__KeyToKey__ KeyCode::CURSOR_DOWN, ModifierFlag::FN | ModifierFlag::CONTROL_L | ModifierFlag::NONE, KeyCode::F4, ModifierFlag::CONTROL_L, KeyCode::PAGEDOWN, KeyCode::F4, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L</autogen>

It also causes a visual glitch, and ⌃F4 sometimes selects windows from hidden applications.

  • These do work as advertised, but the first one makes the frontmost app flash momentarily and the second one works only in Safari. They do have the advantage of correctly acting on the active page of the last app, which is nice. I'm afraid I'm going to award myself the actual answer, though -- although I would like a general solution, I prefer mine to the window flashing and slow performance of AppleScript. – echristopherson Apr 15 '13 at 20:57

I've discovered BetterTouchTool can send arbitrary keys to a certain application, so I set it up to send Page Up and Page Down to Chrome. It doesn't seem to be as general as I'd like (i.e. it can't just send events to the last-selected app; and it can't send actual swipe events to it), but it'll certainly do.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .