我正在尝试向Chrome发送用于查看Flash的URL,同时退出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
答案 0 :(得分: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