V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
yinzhenyu
V2EX  ›  分享创造

Win 转 Mac?一招找回“关闭即退出”的爽快

  •  
  •   yinzhenyu · 22 小时 14 分钟前 · 882 次点击

    macOS 的“关闭窗口 ≠ 退出应用”逻辑,对于强迫症或者刚转系统的朋友来说真的很难受!😫 每次都要 Cmd+Q ,不然 Dock 栏永远一堆小白点。 作为一名喜欢折腾的前端工程师 👨‍💻,我写了一个 BetterTouchTool (BTT) 脚本,完美实现了“点击红叉 = 退出应用”,而且比网上的普通脚本更智能!

    🚀 这个脚本厉害在哪?(逻辑详解)

    • 🤖 智能识别最后一个窗口:只有当那是最后一个窗口时才退出,多窗口时只关当前窗口。
    • 🛡️ 防误触保护:不仅判断窗口数量,还判断了窗口类型!如果你关的是“设置”、“关于”这种弹窗,绝对不会误杀退出整个 App 。
    • ✅ 常用软件白名单:像微信、网易云 这种需要挂后台的软件,脚本会自动放行,只关窗口不退后台!
    • ⚡️ 极速原生体验:底层模拟 Cmd+W ,没有任何延迟。

    🛠️ BTT 设置教程:

    -- 配置你的“保活”应用名单
    set keepAliveApps to {"WeChat", "Telegram", "Spotify", "Music", "DingTalk"}
    
    tell application "System Events"
        set frontApp to first application process whose frontmost is true
        set appName to name of frontApp
        
        -- 白名单检查:如果是常驻应用,只关闭不退出
        if keepAliveApps contains appName then
            keystroke "w" using command down
            return
        end if
        
        -- 获取窗口类型,防止误关设置弹窗
        try
            set currentSubrole to subrole of front window of frontApp
        on error
            set currentSubrole to "Unknown"
        end try
        
        set standardWindowCount to count of (windows of frontApp where subrole is "AXStandardWindow")
    end tell
    
    -- 逻辑判断
    if currentSubrole is not "AXStandardWindow" then
        tell application "System Events" to keystroke "w" using command down
        return
    end if
    
    if standardWindowCount is less than or equal to 1 then
        tell application appName to quit
    else
        tell application "System Events" to keystroke "w" using command down
    end if
    
    10 条回复    2025-11-20 13:04:17 +08:00
    InternetExplorer
        1
    InternetExplorer  
       21 小时 54 分钟前   ❤️ 4
    我有一计:关掉“为打开的应用程序显示指示灯”
    ATiGr
        2
    ATiGr  
       20 小时 35 分钟前
    其实吧,刚转 Mac 我也这样,后来发现这样反而会增加下一次开 app 的延迟(图标多弹个一两下),觉得得不偿失然后就放任不管了。反正日常用系统也不卡,真的卡了再说。
    penisulaS
        3
    penisulaS  
       20 小时 29 分钟前
    其实我在 win 和 mac 下,都很少会关闭打开的 app ,总是开着。反正内存大,还经常用
    p286767375
        4
    p286767375  
       20 小时 15 分钟前
    win 不也有很多 app 点击叉叉后不退出,留在右下角吗?
    而且“每次都要 Cmd+Q” 才完全退出,这个是强大的统一的快捷键啊,比任何工具都好使。
    另外 cmd+option+esc 可以强制退出某个应用
    yinzhenyu
        5
    yinzhenyu  
    OP
       19 小时 50 分钟前
    @p286767375 其实最大的问题是很多应用即使关掉所有的窗口了菜单的当前应用还是没有改变,按照正常的逻辑菜单栏应该显示上个堆叠的应用
    yinzhenyu
        6
    yinzhenyu  
    OP
       19 小时 42 分钟前
    @penisulaS 内存大就是好
    yinzhenyu
        7
    yinzhenyu  
    OP
       19 小时 42 分钟前
    @InternetExplorer 此计亦可
    yinzhenyu
        8
    yinzhenyu  
    OP
       19 小时 40 分钟前
    @ATiGr 看个人习惯吧,我觉得做完工作一阵乱关就挺爽的
    beiguo
        9
    beiguo  
       4 小时 10 分钟前
    @yinzhenyu #8 我也喜欢乱关的爽感,但咱俩的爽点不一样,我喜欢按 Cmd+Q 的爽感,参与感更强。甚至浏览器,我都是用 Cmd+W 把每个 tab 页都关掉再按 Cmd+Q,爽感更持久
    yinzhenyu
        10
    yinzhenyu  
    OP
       55 分钟前 via Android
    @beiguo 看到应用的关闭提示弹窗选择忽略就更爽了
    关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   5396 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 68ms · UTC 06:00 · PVG 14:00 · LAX 22:00 · JFK 01:00
    ♥ Do have faith in what you're doing.