V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
NonClockworkChen
V2EX  ›  问与答

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

  •  
  •   NonClockworkChen · Jun 1, 2017 · 1820 views
    This topic created in 3266 days ago, the information mentioned may be changed or developed.

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

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

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

    Supplement 1  ·  Jun 1, 2017
    Quit all applications except the frontmost
    alfred workflow
    4 replies    2017-06-03 10:56:49 +08:00
    dotpig
        1
    dotpig  
       Jun 1, 2017   ❤️ 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
       Jun 1, 2017
    @dotpig 完美,谢谢.
    我一直在想如何获取当前窗口,原来加个条件'frontmost is false'就行了.
    NonClockworkChen
        3
    NonClockworkChen  
    OP
       Jun 3, 2017
    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
       Jun 3, 2017
    再补充一下,上面的代码要在 run script 中运行,不能再 run NSAppleScript 中运行,没有效果.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3738 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 10:39 · PVG 18:39 · LAX 03:39 · JFK 06:39
    ♥ Do have faith in what you're doing.