Skip to content

Instantly share code, notes, and snippets.

@zthxxx
Last active July 7, 2024 13:28
Show Gist options
  • Save zthxxx/522cd6d2f8de01284c7f4a1a9a894662 to your computer and use it in GitHub Desktop.
Save zthxxx/522cd6d2f8de01284c7f4a1a9a894662 to your computer and use it in GitHub Desktop.
My Hammerspoon config
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