Skip to content

Instantly share code, notes, and snippets.

@MikeBirdTech
Last active September 29, 2023 14:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MikeBirdTech/54d1f54d662b1872b814f8642242f3b9 to your computer and use it in GitHub Desktop.
Save MikeBirdTech/54d1f54d662b1872b814f8642242f3b9 to your computer and use it in GitHub Desktop.
Hammerspoon config for triggering Start Work Day
-- Define the events that should trigger the startWorkDay function
local startWorkDayEvents = {
hs.caffeinate.watcher.systemDidWake,
hs.caffeinate.watcher.screensDidUnlock,
hs.caffeinate.watcher.screensaverDidStop
}
-- Function to check if the event should trigger the startWorkDay function
local function shouldTriggerStartWorkDay(eventType)
for _, startWorkDayEvent in ipairs(startWorkDayEvents) do
if eventType == startWorkDayEvent then
return true
end
end
return false
end
-- Function to run startWorkDay AppleScript
function runStartWorkDayScript()
local ok, result = hs.osascript.applescriptFromFile("/Users/mike/Code/applescripts/StartWorkDay.applescript")
if not ok then
hs.alert.show("StartWorkDay AppleScript failed: " .. result)
end
end
-- Event when system wakes up, unlocks or screensaver stops
hs.caffeinate.watcher.new(function(eventType)
if shouldTriggerStartWorkDay(eventType) then
runStartWorkDayScript()
end
end):start()
-- Event when screen is unlocked
hs.screen.watcher.new(function()
runStartWorkDayScript()
end):start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment