Skip to content

Instantly share code, notes, and snippets.

@narrowtux
Last active August 14, 2017 08:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save narrowtux/03a0360f4341309c590c07b7f94d6959 to your computer and use it in GitHub Desktop.
Save narrowtux/03a0360f4341309c590c07b7f94d6959 to your computer and use it in GitHub Desktop.
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