Last active
December 29, 2015 02:09
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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