hammerspoon 是如何当我当个合格的舔狗的

1 天前
 jassssper

1 、痛点: 在 mac 上聊天的时候 iPhone 手机就一直咚咚的响好烦,如果点击顶部把 ”mac 已登录手机通知关闭“ 的话,又会忘了开,导致女神的消息无法及时回复,被 diss 不是一个合格的舔狗,emm...

2 、观察结论: 如果在 mac 上退出微信的话,手机上的 ”mac 已登录手机通知关闭“ 会自动消掉,手机就能收到通知,从而达到无缝衔接的目的。

3 、解决思路: 使用 hammerspoon 实现如下功能: a.每 30 秒检查一次键盘和鼠标动作,如果 120 秒没有动作就退出 mac 微信(注意不能用 killall ,否则 iPhone 那边不知道 mac 上已经退出了) b.当检测到有鼠标和键盘动作后,立即调起微信登录

4 、具体方法: a.下载、安装、打开 hammerspoon ( https://www.hammerspoon.org/) b.打开配置文件写入脚本:

`local idleLimit = 120 -- 120 秒无操作算不活跃 local checkInterval = 30 -- 每 30 秒检查一次 local wechatBundleID = "com.tencent.xinWeChat"

local timer = nil local enabled = true local lastRunning = nil -- 记录上一次运行状态,避免重复日志

-- 判断微信是否运行 local function isWeChatRunning() return hs.application.get(wechatBundleID) ~= nil end

-- 优雅退出微信 local function quitWeChat(reason) local app = hs.application.get(wechatBundleID) if app then app:kill() hs.alert.show("💤 自动退出微信") print("WeChat quit (" .. (reason or "idle") .. ") at " .. os.date()) lastRunning = false end end

-- 启动微信 local function launchWeChat(reason) if not enabled then return end if not isWeChatRunning() then hs.application.launchOrFocusByBundleID(wechatBundleID) hs.alert.show("🚀 启动微信") print("WeChat launched (" .. (reason or "active") .. ") at " .. os.date()) lastRunning = true end end

-- 检查是否该退出 local function checkIdle() if not enabled then return end local idleTime = hs.host.idleTime() local running = isWeChatRunning()

if running ~= lastRunning then
    print("WeChat running=" .. tostring(running) .. " at " .. os.date())
    lastRunning = running
end

if idleTime > idleLimit and running then
    quitWeChat("idle")
end

end

-- 电源事件监听:休眠时退出微信,唤醒后延迟启动 local sleepWatcher = hs.caffeinate.watcher.new(function(eventType) if eventType == hs.caffeinate.watcher.systemWillSleep then quitWeChat("sleep") elseif eventType == hs.caffeinate.watcher.systemDidWake then hs.timer.doAfter(10, function() launchWeChat("wake") end) elseif eventType == hs.caffeinate.watcher.screensDidSleep then quitWeChat("screens sleep") elseif eventType == hs.caffeinate.watcher.screensDidWake then hs.timer.doAfter(5, function() launchWeChat("screens wake") end) end end) sleepWatcher:start()

-- 定时器:负责检测是否要退出 if timer then timer:stop() end timer = hs.timer.doEvery(checkInterval, checkIdle)

-- 事件监听:键盘/鼠标动作 → 立即启动微信 local eventtap = hs.eventtap.new({ hs.eventtap.event.types.keyDown, hs.eventtap.event.types.mouseMoved, hs.eventtap.event.types.leftMouseDown, hs.eventtap.event.types.rightMouseDown }, function(_) launchWeChat("input") return false end) eventtap:start() ` 后记: 1 、在 iPhone 通知栏可设置 1 小时不提醒,今天不提醒,但是这样也是简单粗暴

2 、微信不像企业微信那样可以设置 5min 10min 无活动就恢复通知

在 AI 大爆发的时代,他们把东西做成这样我表示很痛心

853 次点击
所在节点    Apple
9 条回复
Guino
1 天前
换一个不会 diss 你不合格的女神
jassssper
1 天前
@Guino #1 换不了一点儿
kiev84
1 天前
你想表达是「 hammerspoon 是如何帮我当个合格的舔狗的」吧?标题看了半天没看明白。
huaweii
1 天前
「女神的消息如果不立刻回复我就会失去女神」,请问你是?
zhouweiluan
1 天前
只能说微信这一点是真的智障,QQ 以及企业微信都能监测到电脑长时间无响应会把消息推送到手机,但微信就死活不搞这个,每次都因为离开电脑去吃午饭而错过无数需要及时响应的消息。
jassssper
1 天前
@zhouweiluan #5 试试我上面那个方法就解决啦
kamikaze472
1 天前
手机打开专注模式的工作模式, 微信就不会一直响了
suitts
1 天前
哈哈,我是弄的 mac 锁屏退出微信
killua67
1 天前
我也发现这个问题了,我手机上开了通知,好像只有打开微信界面的时候手机会响,锁屏了不会响,不知道是不是戴了手表的原因 就不推送手机了

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

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

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

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

© 2021 V2EX