Remedy for a sleep problem my MacBook Pro late 2016 has.
displaySleep = false -- Need better way to determine initial state of this variable. But it should be the truth most of the time. | |
systemSleep = false | |
function handleCaffeinateUpdates() | |
wifiPower = hs.wifi.interfaceDetails().power | |
if displaySleep and systemSleep and wifiPower then | |
print("Disabling WiFi before going to sleep") | |
hs.wifi.setPower(false) | |
elseif not displaySleep and not systemSleep and not wifiPower then | |
print("Woke up - enabling wifi") | |
hs.wifi.setPower(true) | |
end | |
end | |
function caffeinateCallback(event) | |
if event == hs.caffeinate.watcher.systemWillSleep then systemSleep = true | |
elseif event == hs.caffeinate.watcher.systemDidWake then systemSleep = false | |
elseif event == hs.caffeinate.watcher.screensDidSleep then displaySleep = true | |
elseif event == hs.caffeinate.watcher.screensDidWake then displaySleep = false | |
end | |
handleCaffeinateUpdates() | |
end | |
sleepWatcher = hs.caffeinate.watcher.new(caffeinateCallback) | |
sleepWatcher:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment