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

Click here to return to the 'Tile Safari windows via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Tile Safari windows via AppleScript
Authored by: lxmorj on Dec 29, '06 11:27:07PM

Thanks for the help. Here is the latest reworking:

tell application "Safari"

-- For some reason Safari has (two) invisible windows
set allWindows to (every window where visible is true)
set n to count of allWindows

-- Get dock position
set dock to do shell script "defaults read orientation"

-- Get actual width to help with left-side docks
tell application "Finder"
set screenSize to bounds of window of desktop
set actualWidth to item 3 of screenSize
end tell

-- Determine space open on your screen, factoring in the Dock
set screenWidth to do JavaScript "screen.availWidth" in document 1
set screenHeight to do JavaScript "screen.availHeight" in document 1

-- Get dock size
set dockSize to actualWidth - screenWidth

-- Get rid of 4 pixel buffer on Dock
if dockSize is 4 then
set dockSize to 0
end if

-- Dividing by zero is bad
if n is equal to 0 then return

-- Determine each window's width
set windowWidth to (screenWidth / n)
set x to 1

-- Position each window in turn
tell window x
-- 21 is the size of the Menu Bar (for 10.4 at least)
if (dock is not equal to "left") then
set bounds to {windowWidth * (x - 1), 21, windowWidth * x, screenHeight}
set bounds to {windowWidth * (x - 1) + dockSize, 21, windowWidth * x + dockSize, screenHeight}
end if
end tell
set x to x + 1
if x is equal to (n + 1) then exit repeat
end repeat
end tell

[ Reply to This | # ]