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 31, '06 12:38:19AM
Factors in Downloads and Source, less redundant : ). Still need a better way to determine the download window. Leads thus far are:
1- It's window id is constant unless Safari is restarted.
2- It's document field is blank.


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
set goodWindows to {}

-- Might run into problems with actual websites titled "Downloads", open for suggestions a more perfect solution : )
repeat with x from 1 to n
set windowX to item x of allWindows
if ((name of windowX does not contain "Source of http://";) and (name of windowX is not "Downloads")) then
set goodWindows to goodWindows & {windowX}
end if
end repeat

set n to count of goodWindows

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


-- 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 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

-- Determine each window's width
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
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 | # ]
Tile Safari windows via AppleScript
Authored by: Frederico on Dec 31, '06 10:55:17AM

"-- Might run into problems with actual websites titled "Downloads", open for suggestions a more perfect solution : )"

The actual downloads window should not have a URL; check for it, and ignore it. e.g.,

set pageURL to URL of document of window 1

You might also want to note under which versions of Safari you have tested this; it breaks on older versions.



[ Reply to This | # ]