解决方式是登录后开关一次,夜览和蓝牙原理一样
1. 终端先安装软件- -- brew install hammerspoon-- brew install smudge/smudge/nightlight-- brew install blueutil
复制代码
2. 脚本内容
默认位置在 ~/.hammerspoon/init.lua- function nightlightControl(state) print('nightlightControl ', state) cmd = "/usr/local/bin/nightlight " .. (state) ok, result = hs.osascript.applescript(string.format('do shell script "%s"', cmd)) return resultendfunction bluetoothControl(state) cmd = "blueutil -p " .. (state) ok, result = hs.osascript.applescript(string.format('do shell script "%s"', cmd)) return resultendfunction caffeinateCallback(eventType) if (eventType == hs.caffeinate.watcher.screensDidSleep) then bluetoothControl("0") elseif (eventType == hs.caffeinate.watcher.screensDidWake) then bluetoothControl("1") elseif (eventType == hs.caffeinate.watcher.screensDidUnlock) then if (string.match(nightlightControl('status'), 'on')) then nightlightControl('off') nightlightControl('on') end endendcaffeinateWatcher = hs.caffeinate.watcher.new(caffeinateCallback)caffeinateWatcher:start()
复制代码 OR |