One of the easiest ways to do this is to use BetterTouchTool. It will let you bind a keyboard shortcut or a trackpad shortcut to many commands, including maximize window.
Once you are in the BTT settings page, do the following:
- Go to the Keyboard tab on top.
- On the bottom near Keyboard shortcut, enter in whichever keyboard shortcut you want.
- For Predefined action, choose Maximize Window.
There are many other options related to maximizing besides "Maximize Window":
- Maximize Window Left
- Maximize Window Right
- Maximize Window To Bottom Half
- Maximize Window To Top Half
- Maximize To Next Monitor
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.
Best Answer
I worked it out.
A long press on the green button then allows you to drag it to the half of the screen you want. (Better touch tool not required, default MacOS behaviour)