Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Tile windows horizontally and vertically' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Tile windows horizontally and vertically
Authored by: isherman on Feb 03, '08 04:36:09AM

I've modified the script that tiles windows so that all visible windows are shown side-by-side, and tiled both horizontally and vertically:

property horizontalSpacing : 10 -- sets the horizontal spacing between windows
property verticalSpacing : 10 -- sets the vertical spacing between windows

-- Find screen bounds
tell application "Finder"
set screenSize to bounds of window of desktop
set availScreenWidth to item 3 of screenSize
set availScreenHeight to item 4 of screenSize
end tell

-- Account for space occupied by dock if dock is on the bottom and not hidden
tell application "System Events"
set dockProps to property list file "~/Library/Preferences/com.apple.dock.plist"
set docVisible to not the value of the property list item "autohide" of dockProps
set dockSide to the value of the property list item "orientation" of dockProps
set dockTileSize to the value of the property list item "tilesize" of dockProps
end tell
if docVisible and dockSide is "bottom" then
set availScreenHeight to availScreenHeight - (dockTileSize + 10)
end if

-- Select current application as the application whose windows to tile
tell application "System Events"
set myFrontMost to name of first item of (processes whose frontmost is true)
end tell

-- Top margin correction factor
if myFrontMost is "Finder" then
set myTopCorr to 44
else
set myTopCorr to 22
end if

-- Tile the windows
try
tell application myFrontMost
set allWindows to (every window where visible is true)
set n to count of allWindows
set nPerAxis to (square root of (n as real)) -- if n is a perfect square, sqrt(n) windows will be shown on each row and column
set nColumns to round (ceiling of nPerAxis) rounding as taught in school -- otherwise, prefer to have more columns than rows
set nRows to round (floor of nPerAxis) rounding as taught in school
set nSpacingWidth to (nColumns - 1) * horizontalSpacing
set nSpacingHeight to (nRows - 1) * verticalSpacing
set nWindowWidth to (availScreenWidth - nSpacingWidth) / nColumns
set nWindowHeight to (availScreenHeight - myTopCorr - nSpacingHeight) / nRows
repeat with x from 1 to n
tell window x
set nLeft to ((x - 1) mod nColumns) * (horizontalSpacing + nWindowWidth)
set nTop to myTopCorr + ((x - 1) div nColumns) * (verticalSpacing + nWindowHeight)
set bounds to {¬
nLeft, ¬
nTop, ¬
nLeft + nWindowWidth, ¬
nTop + nWindowHeight}
end tell
end repeat
end tell
on error the error_message number the error_number
display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try



[ Reply to This | # ]