

before predicateFn returns true) if desired. The timer is passed as an argument to actionFn so that it may stop the timer prematurely (i.e.checkInterval - an optional parameter indicating how often to repeat the predicateFn check.This function may take a single argument, the timer itself. actionFn - a function which performs the desired action.This function takes no arguments, but should return true when it is time to stop calling actionFn. predicateFn - a function which determines when to stop calling actionFn.The timer is automatically stopped when predicateFn returns true. Hs.timer.doUntil(predicateFn, actionFn) -> timerĬreates and starts a timer which will perform actionFn every checkinterval seconds until predicateFn returns true. This function is a shorthand for hs.timer.new(interval, fn):start().fn - A function to call every time the timer triggers.interval - A number of seconds between triggers.To run a job every hour on the hour from 8:00 to 20:00: for h=8,20 do hs.timer.doAt(h.":00","1d",runJob) end.If it's 21:00, hs.timer.doAt("20:00",somefn) will set the timer 23 hours from now.

If it's 19:00, hs.timer.doAt("20:00",somefn) will set the timer 1 hour from now.Of when Hammerspoon was restarted/reloaded. Results in exactly 24 hours you can schedule regular jobs that will run at the expected time independently The first trigger will be set to the earliest occurrence given the repeatInterval if that's omitted,Īnd time is earlier than the current time, the timer will trigger the next day.The timer can trigger up to 1 second early or late.

continueOnError - an optional boolean flag, defaulting to false, which indicates that the timer should not be automatically stopped if the callback function results in an error.fn - a function to call every time the timer triggers.repeatInterval - (optional) number of seconds between triggers, or a string in the format "DDd", "DDdHHh", "HHhMMm", "HHh" or "MMm" indicating days, hours and/or minutes between triggers if omitted or 0 the timer will trigger only once.time - number of seconds after (local) midnight, or a string in the format "HH:MM" (24-hour local time), indicating the desired trigger time.Hs.timer.doAt(time, fn) -> timerĬreates and starts a timer which will perform fn at the given (local) time and then (optionally) repeat it every interval. The callback can be cancelled by calling the :stop() method on the returned object before sec seconds have passed.There is no need to call :start() on the returned object, the timer will be already running.sec - A number of seconds to wait before calling the function.
TAGDIDCHANGE EVENT HAMMERSPOON CODE
For all other purposes, you really should be splitting up your code into multiple functions and calling hs.timer.doAfter() This is only provided as a last resort, or for extremely short sleeps. This means no hotkeys or events will be processed in that time, no GUI updates will happen, and no Lua will execute.
