Subscribe

Sunday, February 25, 2007

AppleScript to Quit All Open Apps-退出全部运行程序的AppleScript代码

Steve Jobs在WWDC发表的主题演讲中点击了Dock中的一个AppleScript图标退出了当时正在运行的全部应用程序, 今天在MacOsxHint的论坛里看到有人提供了这个AppleScript, 测试后运行成功. 在ScriptEditor中把下面这段as另存为application, 命名并保存在某个文件夹. 然后点击该application并拖到Dock中保留. 在Dock中点击该图标即可退出全部运行的应用程序(包括该AppleScript本身):

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