macOS 的“关闭窗口 ≠ 退出应用”逻辑,对于强迫症或者刚转系统的朋友来说真的很难受!😫 每次都要 Cmd+Q ,不然 Dock 栏永远一堆小白点。 作为一名喜欢折腾的前端工程师 👨💻,我写了一个 BetterTouchTool (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
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.