Forked from boringrgb/hammerspoon_sleep_script.lua
Created
November 11, 2019 05:27
-
-
Save confluencepoint/f43513ef78fcb71fffc2ccc3f6d459a2 to your computer and use it in GitHub Desktop.
This tiny script goes into your Hammerspoon configuration and it hooks on the lid open/close event
This file contains hidden or 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 sleepWatch(eventType) | |
| local action = "unknown" | |
| if (eventType == hs.caffeinate.watcher.systemWillSleep) then | |
| hs.alert.show("Going to sleep!") | |
| host = hs.host.localizedName() | |
| action = "sleep" | |
| elseif (eventType == hs.caffeinate.watcher.systemDidWake) then | |
| hs.alert.show("Waking up!") | |
| action = "awake" | |
| end | |
| -- write current state of laptop lid to file | |
| if (action ~= "unknown") then | |
| filename = string.format("%s/mylaptoplid.txt", os.getenv( "HOME" )) | |
| local f = assert(io.open(filename, "a+")) | |
| local tstamp = os.date("%d/%m/%y %H:%M:%S") | |
| local s = string.format("%s %s\n", tstamp, action) | |
| f:write( s ) | |
| f:flush() | |
| f:close() | |
| end | |
| end | |
| local sleepWatcher = hs.caffeinate.watcher.new(sleepWatch) | |
| sleepWatcher:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment