Applescript 替代';退出';命令

Applescript 替代';退出';命令,applescript,Applescript,我知道这个问题的标题看起来很奇怪,所以我会尝试更好地解释:我知道你可以通过这样做让应用程序退出: tell application "whatever" to quit 我想知道是否有其他办法可以这样做 提前感谢。您可以像这样使用GUI脚本编写 tell application "System Events" to tell process "whatever" to keystroke "q" using {command down} 告诉应用程序“无论什么”退出方法的问题在于,您只能在编

我知道这个问题的标题看起来很奇怪,所以我会尝试更好地解释:我知道你可以通过这样做让应用程序退出:

tell application "whatever" to quit
我想知道是否有其他办法可以这样做


提前感谢。

您可以像这样使用
GUI脚本编写

tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}

告诉应用程序“无论什么”退出方法的问题在于,您只能在编译脚本时将目标应用程序安装在您的计算机上。下面是一个AppleScript,它确定所有正在运行的应用程序进程的名称,然后通过发送
quit
命令退出每个进程

property pExcludeApps : {"Finder", name of current application}

tell application "System Events"
    set theAppsToQuit to name of every process where background only = false
end tell

repeat with theApp in theAppsToQuit
    if pExcludeApps does not contain contents of theApp then
        tell application (contents of theApp)
            quit saving yes
        end tell
    end if
end repeat



@Antal S-Z我猜OP只是想了解更多关于AppleScript的信息。
delay 5
tell application (path to frontmost application as text) to quit saving no
delay 5
tell application "System Events" to set pid to unix id of (process 1 where frontmost is true)
do shell script "kill " & pid
tell application "TextEdit" to close windows
tell application "System Events" to tell process "TextEdit" to set visible to false
-- Lion will auto-terminate the app