Last active
September 29, 2023 14:09
-
-
Save MikeBirdTech/54d1f54d662b1872b814f8642242f3b9 to your computer and use it in GitHub Desktop.
Hammerspoon config for triggering Start Work Day
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
-- 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