https://www.alfredforum.com/topic/2909-quit-all-applications-except-the-frontmost/
就是退出 all app,但是不要把正在用的 quit 掉.
年代太久了,作者的文件链接已经失效了
1
dotpig 2017-06-01 15:50:18 +08:00 1
这样可以吗?
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" repeat with closeall in quitapps quit application closeall end repeat |
2
NonClockworkChen OP @dotpig 完美,谢谢.
我一直在想如何获取当前窗口,原来加个条件'frontmost is false'就行了. |
3
NonClockworkChen OP 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 子程序,替换名字. |
4
NonClockworkChen OP 再补充一下,上面的代码要在 run script 中运行,不能再 run NSAppleScript 中运行,没有效果.
|