我知道問題的標題看起來奇怪,所以我會試着更好的解釋:我知道你可以通過這樣退出應用程序:替代「退出」命令
tell application "whatever" to quit
我想知道是否有是否可以做到這一點。
在此先感謝。
我知道問題的標題看起來奇怪,所以我會試着更好的解釋:我知道你可以通過這樣退出應用程序:替代「退出」命令
tell application "whatever" to quit
我想知道是否有是否可以做到這一點。
在此先感謝。
您可以使用GUI Scripting
這樣的...
tell application "System Events" to tell process "whatever" to keystroke "q" using {command down}
與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
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
你爲什麼要這麼做? –
@Antal S-Z我猜OP只是想了解更多關於AppleScript的知識。 – fireshadow52