Maximise OS X windows with a keyboard shortcut

Save this Applescript in ~/Library/Scripts, assign a keyboard shortcut to it with Quicksilver (Triggers) and hey presto:

set resolution to words of (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution")
set {width, height} to {item 2, item 4} of resolution

tell application (path to frontmost application as string)
  set bounds of front window to {0, 22, width, height}
end tell

Doesn't seem to work in all applications though...

Update: Sven's solution should work in all applications, even those that don't support Applescript:


set resolution to words of (do shell script "/usr/sbin/system_profiler SPDisplaysDataType | grep Resolution")
set {width, height} to {item 2, item 4} of resolution

tell application "System Events"
  tell (first process whose frontmost is true)
    set position of first window to {0, 22}
    set size of first window to {width, height}
  end tell
end tell

Comments

I'd say this should fail for apps without AppleScript support (hello Preview!).

Going the SystemEvents route may be better

tell application "System Events"
set p to first process whose frontmost is true
tell p
set position of first window to {0, 22}
set size of first window to {width, height}
end tell
end tell

Unfortunately both solutions fail to take into account the Dock position.

Thanks Sven, that seems to work better. I always have the Dock hidden anyway.

PS That should probably read 'height-22' somewhere, to make sure windows actually fit on screen. (Cocoa apps seem to correct this problem automatically, though.)

Awesome.
I've been looking for something like this.

Oh, don't forget to turn on
"Enable access for assistive devices" under Universal Access

Thanks.

All fields are optional, email address will not be shown; no HTML, URLs are automatically hyperlinked.