预期的行尾等,但找到了标识符。指向JavaScript

时间:2014-08-29 11:16:59

标签: javascript safari window applescript tile

找到这个很棒的脚本,但无法让它工作......继续获得“预期的行尾等,但找到了标识符。”错误指向“JavaScript” - 第11节???

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

0 个答案:

没有答案