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 Jan 06, '07 11:40:02AM

Perfected : ) (Although perhaps not optimized)

--Tested only on a 17in Powerbook G4 running 10.4.8, Safari Version 2.0.4
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

--This list will exclude all Source windows, and the Download window
set goodWindows to {}

repeat with x from 1 to n
set windowX to item x of allWindows
if (URL of document of windowX exists) then
set goodWindows to goodWindows & {windowX}
end if
end repeat

set n to count of goodWindows

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

-- If Downloads or Source window is frontmost, screenWidth and screenHeight will not be defined
set goodDoc to document of first item of goodWindows

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

-- Get actual width of screen 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 goodDoc
set screenHeight to do JavaScript "screen.availHeight" in goodDoc

-- Get dock size
set dockSize to actualWidth - screenWidth

-- Get rid of pixel buffer on Dock
set screenHeight to screenHeight + 26

-- Determine desired width of each window
set windowWidth to (screenWidth / n)

-- Position each window in turn
repeat with x from 1 to n
tell item x of goodWindows
set index to 1 --Makes sure the Source and Downloads windows are behind the tiled ones
if (dock is not equal to "left") then --Coordinates are measured from the upper left corner, so the left-side dock is the special case

set bounds to {windowWidth * (x - 1), 21, windowWidth * x, screenHeight} -- 21 is the size of the Menu Bar (for 10.4 at least)

else
set bounds to {windowWidth * (x - 1) + dockSize, 21, windowWidth * x + dockSize, screenHeight}
end if
end tell
end repeat

end tell



[ Reply to This | # ]