Last active
July 7, 2024 13:28
-
-
Save zthxxx/522cd6d2f8de01284c7f4a1a9a894662 to your computer and use it in GitHub Desktop.
My Hammerspoon config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function shell(command) | |
ok, result = hs.osascript.applescript(string.format('do shell script "%s"', command)) | |
return result | |
end | |
function sleep(n) | |
os.execute('sleep ' .. tonumber(n)) | |
end | |
-- https://github.com/smudge/nightlight | |
function nightlight(command) | |
return shell('/usr/local/bin/nightlight ' .. command) | |
end | |
function rerunNightlight() | |
if (string.match(nightlight('status'), 'on until')) then | |
nightlight('off') | |
sleep(0.2) | |
nightlight('on') | |
end | |
end | |
function caffeinateCallback(eventType) | |
if (eventType == hs.caffeinate.watcher.screensDidUnlock) then | |
rerunNightlight() | |
end | |
end | |
caffeinateWatcher = hs.caffeinate.watcher.new(caffeinateCallback) | |
caffeinateWatcher:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment