V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
NonClockworkChen
V2EX  ›  问与答

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

  •  
  •   NonClockworkChen · 2017-06-01 10:22:26 +08:00 · 1237 次点击
    这是一个创建于 2492 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    第 1 条附言  ·  2017-06-01 16:02:06 +08:00
    Quit all applications except the frontmost
    alfred workflow
    4 条回复    2017-06-03 10:56:49 +08:00
    dotpig
        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
    NonClockworkChen
        2
    NonClockworkChen  
    OP
       2017-06-01 16:00:33 +08:00
    @dotpig 完美,谢谢.
    我一直在想如何获取当前窗口,原来加个条件'frontmost is false'就行了.
    NonClockworkChen
        3
    NonClockworkChen  
    OP
       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
        4
    NonClockworkChen  
    OP
       2017-06-03 10:56:49 +08:00
    再补充一下,上面的代码要在 run script 中运行,不能再 run NSAppleScript 中运行,没有效果.
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1532 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:06 · PVG 01:06 · LAX 10:06 · JFK 13:06
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.