Skip to content

Instantly share code, notes, and snippets.

@ap
Last active December 29, 2015 02:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ap/7598606 to your computer and use it in GitHub Desktop.
Save ap/7598606 to your computer and use it in GitHub Desktop.
Takes the frontmost window, maximises it vertically, and centres it horizontally if it was off-screen
tell application "Finder"
set {dx1, dy1, dx2, dy2} to bounds of window of desktop
end tell
set cur_app to (path to frontmost application as Unicode text)
tell application cur_app
set {x1, y1, x2, y2} to bounds of front window
if x1 < dx1 or x2 > dx2 then
set displayWidth to dx2 - dx1
set windowWidth to x2 - x1
set padWidth to (displayWidth - windowWidth) / 2
set x1 to dx1 + padWidth
set x2 to dx2 - padWidth
end if
tell front window
set bounds to {x1, dy1, x2, dy2}
end tell
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment