NonClockworkChen
2017-06-03 10:05:44 +08:00
tell application "System Events" to set quitapps to name of every application process whose visible is true and frontmost is false and name is not "Finder"
get quitapps
replace_matches(quitapps, "Electron", "Code", false)
repeat with closeall in quitapps
try
quit application closeall
end try
end repeat
get quitapps
on replace_matches(this_list, match_item, replacement_item, replace_all)
repeat with i from 1 to the count of this_list
set this_item to item i of this_list
if this_item is the match_item then
set item i of this_list to the replacement_item
if replace_all is false then return this_list
end if
end repeat
return this_list
end replace_matches
补充一下,因为 Visual Studio Code 比较特殊,居然获得名字叫 Electron,无法关闭.所以需要将 quitapps 中的 Electron 替换成 Code(VSC 在 monitor 中的名字).
如果碰上类似情况的 app,可以重复调用 replace_matches 子程序,替换名字.