Created
July 4, 2010 18:15
-
-
Save prashanta/463636 to your computer and use it in GitHub Desktop.
Cascade windows
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
set applist to getFrontApp() | |
-- screen resolution | |
set screen to {1280, 800} | |
set menubar to getMenuSize() | |
set dock to getDockSize() | |
set a to item 1 of getFrontApp() | |
set t to (item 2 of menubar) | |
set l to 0 | |
set h to 600 | |
-- special with for iChat and Skype windows | |
if a contains "iChat" or a contains "Skype" then | |
set w to 400 | |
else | |
set w to 800 | |
end if | |
tell application a | |
set allWindows to (every window where visible is true) | |
set wins to count of allWindows | |
end tell | |
set diffx to ((item 1 of screen) - w) / (wins - 1) | |
set diffy to ((item 2 of screen) - h - (item 2 of menubar) - (item 2 of dock)) / (wins - 1) | |
-- Special case for Terminal windows (ref: http://openradar.appspot.com/5765608) | |
if a contains "Terminal" then | |
tell application "Terminal" | |
activate | |
repeat with aWindow in (get every window) | |
set winBounds to bounds of front window | |
set height to (item 4 of winBounds) - (item 2 of winBounds) | |
set bounds of aWindow to {l, t + height, w, h + height} | |
set t to t + diffy | |
set l to l + diffx | |
set h to diffy + h | |
set w to diffx + w | |
end repeat | |
end tell | |
else | |
-- for rest of the applications | |
tell application a | |
activate | |
repeat with aWindow in (get every window) | |
set bounds of aWindow to {l, t, w, h} | |
set t to t + diffy | |
set l to l + diffx | |
set h to diffy + h | |
set w to diffx + w | |
end repeat | |
end tell | |
end if | |
-- ----------------------- | |
on getFrontApp() | |
tell application "System Events" to set frontwin to name of every process whose frontmost is true and visible ≠ false | |
return frontwin | |
end getFrontApp | |
-- ----------------------- | |
on getDockSize() | |
-- ref: http://www.j4mie.org/2008/05/26/how-to-get-the-dimensions-of-the-dock/comment-page-1/#comment-156011 | |
tell application "System Events" to tell process "Dock" | |
set dock_dimensions to size in list 1 | |
set dock_width to item 1 of dock_dimensions | |
set dock_height to item 2 of dock_dimensions | |
end tell | |
return {dock_width, dock_height} | |
end getDockSize | |
-- ----------------------- | |
on getMenuSize() | |
tell application "System Events" | |
set {menuBarWidth, menuBarHeight} to size of UI element 1 of application process "SystemUIServer" | |
end tell | |
return {menuBarWidth, menuBarHeight} | |
end getMenuSize |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment