以下示例 AppleScript 代码非常简单,并且会优雅地退出所选应用程序,前提是所选应用程序处于稳定状态:
tell application "System Events" to ¬
set appList to the name of ¬
every process whose visible is true
set quitAppList to ¬
choose from list appList ¬
with multiple selections allowed
repeat with thisApp in quitAppList
quit application thisApp
end repeat
当我展示一个可供选择的列表时,我更喜欢按字母顺序排列它,为此我使用一个处理程序在展示它之前首先对列表进行排序:
on SortList(thisList)
set indexList to {}
set sortedList to {}
set theCount to (count thisList)
repeat theCount times
set lowItem to ""
repeat with i from 1 to theCount
if i is not in the indexList then
set thisItem to item i of thisList as text
if lowItem is "" then
set lowItem to thisItem
set lowItemIndex to i
else if thisItem comes before lowItem then
set lowItem to thisItem
set lowItemIndex to i
end if
end if
end repeat
set end of sortedList to lowItem
set end of indexList to lowItemIndex
end repeat
return the sortedList
end SortList
要将其与呈现的第一个代码块一起使用,我通常在代码底部添加处理程序,然后要使用它,请在and语句之间添加以下示例AppleScript代码: tell application "Finder" to ¬
set quitAppList to ¬
set appList to SortList(appList)
注意:多年前,我在Internet上的某个地方获得了这个特殊的处理程序,以至于记不清了,不幸的是,我失去了它的功劳。无论你是谁,我都向你道歉。