求一个 2013 年的 alfred 的 workflow,google 搜不到了

2017-06-01 10:22:26 +08:00
 NonClockworkChen

https://www.alfredforum.com/topic/2909-quit-all-applications-except-the-frontmost/

就是退出 all app,但是不要把正在用的 quit 掉.

年代太久了,作者的文件链接已经失效了

1249 次点击
所在节点    问与答
4 条回复
dotpig
2017-06-01 15:50:18 +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"
repeat with closeall in quitapps
quit application closeall
end repeat
NonClockworkChen
2017-06-01 16:00:33 +08:00
@dotpig 完美,谢谢.
我一直在想如何获取当前窗口,原来加个条件'frontmost is false'就行了.
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 子程序,替换名字.
NonClockworkChen
2017-06-03 10:56:49 +08:00
再补充一下,上面的代码要在 run script 中运行,不能再 run NSAppleScript 中运行,没有效果.

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/365121

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX