Last active
November 14, 2021 15:58
-
-
Save dropmeaword/cbf03189897733cbef6267dfbf36861d 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 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