可以使用 Hammerspoon 的监听合上本子后 Eject 移动硬盘,参考下面的方式进行实现。
-- 系统事件监听回调函数,事件类型可参考
https://www.hammerspoon.org/docs/hs.caffeinate.watcher.html-- 系统休眠时关闭蓝牙:
https://gist.github.com/ysimonson/fea48ee8a68ed2cbac12473e87134f58function watchCallback(event)
-- 18 点后休眠时才自动关闭蓝牙
local hour =
os.date("*t").hour
if event == hs.caffeinate.watcher.systemWillSleep and hour >= 18 then
hs.execute("/opt/homebrew/bin/blueutil -p 0")
end
if event == hs.caffeinate.watcher.systemWillSleep then
-- 关闭无线
hs.execute("networksetup -setairportpower en0 off")
end
if event == hs.caffeinate.watcher.systemDidWake then
-- 打开无线
hs.execute("networksetup -setairportpower en0 on")
end
end
watcher = hs.caffeinate.watcher.new(watchCallback)
watcher:start()