'quit'命令的替代选择

时间:2011-08-08 20:34:55

标签: applescript

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

tell application "whatever" to quit

我想知道是否有其他替代方法。

提前致谢。

3 个答案:

答案 0 :(得分:1)

您可以像这样使用GUI Scripting ......

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

答案 1 :(得分:1)

tell application "whatever" to quit方法的问题在于,您只能在编译脚本时定位计算机上安装的应用程序。这是一个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

答案 2 :(得分:1)

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