1

我正在尝试将 URL 发送到 chrome 以查看 flash,同时退出 Safari,以免耗尽内存,然后在我退出 Chrome 后立即返回 Safari。在我退出 Chrome 后,无法预料会返回 Safari,因此我需要有关重复循环的帮助。我想将其作为服务运行。谢谢!

property theURL : ""

on run {input, parameters}

tell application "Google Chrome"
    activate
end tell

tell application "Safari"
    activate
end tell

tell application "System Events"
    keystroke "j" using {command down} -- Highlight the URL field.
    keystroke "c" using {command down}
    keystroke "w" using {command down}
end tell

delay 0.1

tell application "Safari"
    quit
end tell

tell application "Google Chrome"
    if (count of (every window where visible is true)) is greater than 0 then
        tell front window
            make new tab
        end tell
    else
        make new window
    end if
    set URL of active tab of front window to the clipboard
    activate
end tell

repeat
    if application "Google Chrome" is not running then exit repeat
    delay 5
end repeat

tell application "Safari"
    activate
end tell

return input
 end run

更新!这是工作脚本:

 property theURL : ""

 on run

tell application "Safari"
    activate
    set theURL to URL of document 1
    quit
end tell


tell application "Google Chrome"
    activate
    if (count of (every window where visible is true)) is greater than 0 then
        tell front window
            make new tab
        end tell
    else
        make new window
    end if
    set URL of active tab of window 1 to theURL
    activate tab 1
end tell

repeat
    tell application "System Events"
    if "Google Chrome" is not in (name of application processes) then exit repeat
    end tell
    delay 5
end repeat

tell application "Safari"
    activate
end tell


end run
4

1 回答 1

3

你可以试试这个...

repeat
    tell application "System Events"
        if "Google Chrome" is not in (name of application processes) then exit repeat
    end tell
    delay 5
end repeat

此外,如果可以避免的话,我总是避免使用击键和其他 gui 脚本。它们不是 100% 可靠的。因此,我建议您像这样转移网址...

tell application "Safari" to set theURL to URL of document 1

和...

tell application "Google Chrome" to set URL of active tab of window 1 to theURL
于 2012-04-22T02:23:00.380 回答