如何使用Applescript退出所有正在運行的用戶應用程序?使用Applescript退出所有應用程序?
12
A
回答
10
沒事......我想我找到我的答案:
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
0
tell application "System Events" to set quitapps to name of every application process whose visible is true and name is not "Finder"
repeat with closeall in quitapps
quit application closeall
end repeat
1
tell application "System Events" to set the visible of every process to true
set white_list to {"Finder"}
try
tell application "Finder"
set process_list to the name of every process whose visible is true
end tell
repeat with i from 1 to (number of items in process_list)
set this_process to item i of the process_list
if this_process is not in white_list then
tell application this_process
quit
end tell
end if
end repeat
on error
tell the current application to display dialog "An error has occurred!" & return & "This script will now quit" buttons {"Quit"} default button 1 with icon 0
end try
0
一些google搜索後,我發現了一個更好的方法:
- 它使用
background only
建設最初的應用程序列表,而不是visible is true
。區別在於其他腳本將失敗 以退出使用⌘H隱藏的應用程序。 - 它提供了一個排除列表 列表,因此,例如,您可以在每次測試腳本時阻止腳本編輯器從 退出。
-- get list of open apps
tell application "System Events"
set allApps to displayed name of (every process whose background only is false) as list
end tell
-- leave some apps open
set exclusions to {"AppleScript Editor", "Automator", "Finder", "LaunchBar"}
-- quit each app
repeat with thisApp in allApps
set thisApp to thisApp as text
if thisApp is not in exclusions then
tell application thisApp to quit
end if
end repeat
相關問題
- 1. 無法退出AppleScript應用程序
- 2. Single退出使用Auth0的所有應用程序
- 3. Applescript - 列出所有正在運行的應用程序
- 4. 如何使用AppleScript關閉所有隱藏的應用程序?
- 5. 執行shell腳本後退出applescript應用程序
- 6. AppleScript,按ID退出應用程序,安全
- 7. 在AppleScript中關閉窗口後退出應用程序
- 8. 退出應用程序時是否應關閉所有資源?
- 9. 退出Android應用程序 - 殺死所有進程
- 10. 使用UIAlertController退出應用程序
- 11. 使用確認退出應用程序
- 12. WP7 PhoneGap應用程序後退按鈕退出應用程序
- 13. 退出Android應用程序
- 14. 退出Android應用程序
- 15. 退出應用程序Android
- 16. 退出應用程序
- 17. 應用程序不退出:
- 18. 退出iphone應用程序
- 19. 應用程序退出
- 20. OnBackPressed()退出應用程序
- 21. 退出應用程序iOS
- 22. OnBackPressing退出應用程序
- 23. Android:退出應用程序
- 24. 退出Android應用程序
- 25. SegFault退出應用程序
- 26. 退出iPhone應用程序?
- 27. BackButton退出應用程序
- 28. 所有可能的方式退出.net應用程序?
- 29. 刪除應用程序退出前的所有文件
- 30. 可可 - 強制退出所有其他應用程序
好東東。需要注意的一點是,操作系統(至少在10.7.4)會在最後一次應用程序退出時自動激活Finder - 顯示非最小化窗口。如果你更喜歡桌面的清晰視圖,你可以最小化所有的Finder窗口,`告訴應用程序「系統事件」點擊(每個窗口中的第一個按鈕「Finder」,其角色描述是「最小化按鈕」), /或關閉它們全部,`告訴應用程序「Finder」關閉每個窗口「。如果關閉它們,則先將它們最小化,以防止閃爍。 – mklement0 2012-05-14 14:12:49
雖然使用流程類的`name`屬性_usually_有效,但有些應用程序的值與UI中顯示的應用程序名稱不同,並且可以通過`tell application`語句來理解。因此,最好使用「顯示名稱」屬性(儘管可能仍然存在即使這樣也不起作用的情況)。因此,上面的相關行應該是`將process_list設置爲顯示爲真的每個進程的顯示名稱。 – mklement0 2012-05-26 22:13:23