如何在AppleScript中等待退出操作?

如何在AppleScript中等待退出操作?,applescript,Applescript,我正在尝试向chrome发送一个URL以查看flash,同时退出Safari,这样它就不会占用内存,然后一旦退出chrome,就返回Safari。在我退出Chrome之后,不可能再回到Safari,所以我需要重复循环的帮助。我想将其作为服务运行。谢谢 property theURL : "" on run {input, parameters} tell application "Google Chrome" activate end tell tell application "

我正在尝试向chrome发送一个URL以查看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
你可以试试这个

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%可靠的。因此,我建议你像这样传输url

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