hs.timer
Module
Module for creating and managing timers
Types
This module provides the following types:
Properties
hs.timer.doUntil
JSValue
Repeat a function until a predicate returns true. Swift-retained storage for the JS implementation.
hs.timer.doWhile
JSValue
Repeat a function while a predicate returns true. Swift-retained storage for the JS implementation.
hs.timer.waitUntil
JSValue
Wait to call a function until a predicate returns true. Swift-retained storage for the JS implementation.
hs.timer.waitWhile
JSValue
Wait to call a function until a predicate returns false. Swift-retained storage for the JS implementation.
Methods
hs.timer.create
Create a new timer
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:21
Declaration
hs.timer.create(interval, callback, continueOnError) -> HSTimer
Parameters
-
intervalnumberThe interval in seconds at which the timer should fire
-
callbackJSValueA JavaScript function to call when the timer fires
-
continueOnErrorbooleanIf true, the timer will continue running even if the callback throws an error
Return Value
A timer object. Call start() to begin the timer.
hs.timer.new
Create a new timer (alias for create())
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:30
Declaration
hs.timer.new(interval, callback, continueOnError) -> HSTimer
Parameters
-
intervalnumberThe interval in seconds at which the timer should fire
-
callbackJSValueA JavaScript function to call when the timer fires
-
continueOnErrorbooleanIf true, the timer will continue running even if the callback throws an error
Return Value
A timer object. Call start() to begin the timer.
hs.timer.doAfter
Create and start a one-shot timer
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:37
Declaration
hs.timer.doAfter(seconds, callback) -> HSTimer
Parameters
-
secondsnumberNumber of seconds to wait before firing
-
callbackJSValueA JavaScript function to call when the timer fires
Return Value
A timer object (already started)
hs.timer.doEvery
Create and start a repeating timer
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:44
Declaration
hs.timer.doEvery(interval, callback) -> HSTimer
Parameters
-
intervalnumberThe interval in seconds at which the timer should fire
-
callbackJSValueA JavaScript function to call when the timer fires
Return Value
A timer object (already started)
hs.timer.doAt
Create and start a timer that fires at a specific time
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:54
Declaration
hs.timer.doAt(time, repeatInterval, callback, continueOnError) -> HSTimer
Parameters
-
timenumberSeconds since midnight (local time) when the timer should first fire
-
repeatIntervalnumberIf provided, the timer will repeat at this interval. Pass 0 for one-shot.
-
callbackJSValueA JavaScript function to call when the timer fires
-
continueOnErrorbooleanIf true, the timer will continue running even if the callback throws an error
Return Value
A timer object (already started)
hs.timer.usleep
Block execution for a specified number of microseconds (strongly discouraged)
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:59
Declaration
hs.timer.usleep(microseconds) -> None
Parameters
-
microsecondsnumberNumber of microseconds to sleep
Return Value
None
hs.timer.secondsSinceEpoch
Get the current time as seconds since the UNIX epoch with sub-second precision
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:63
Declaration
hs.timer.secondsSinceEpoch() -> number
Parameters
None
Return Value
Fractional seconds since midnight, January 1, 1970 UTC
hs.timer.absoluteTime
Get the number of nanoseconds since the system was booted (excluding sleep time)
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:67
Declaration
hs.timer.absoluteTime() -> UInt64
Parameters
None
Return Value
Nanoseconds since boot
hs.timer.localTime
Get the number of seconds since local midnight
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:71
Declaration
hs.timer.localTime() -> number
Parameters
None
Return Value
Seconds since midnight in the local timezone
hs.timer.minutes
Converts minutes to seconds
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:76
Declaration
hs.timer.minutes(n) -> number
Parameters
-
nnumberA number of minutes
Return Value
The equivalent number of seconds
hs.timer.hours
Converts hours to seconds
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:81
Declaration
hs.timer.hours(n) -> number
Parameters
-
nnumberA number of hours
Return Value
The equivalent number of seconds
hs.timer.days
Converts days to seconds
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:86
Declaration
hs.timer.days(n) -> number
Parameters
-
nnumberA number of days
Return Value
The equivalent number of seconds
hs.timer.weeks
Converts weeks to seconds
Hammerspoon 2/Modules/hs.timer/HSTimerModule.swift:91
Declaration
hs.timer.weeks(n) -> number
Parameters
-
nnumberA number of weeks
Return Value
The equivalent number of seconds
hs.timer.doUntil
Repeat a function/lambda until a given predicate function/lambda returns true
Hammerspoon 2/Modules/hs.timer/hs.timer.js:18
Declaration
hs.timer.doUntil(predicateFn, actionFn, checkInterval) -> None
Parameters
-
predicateFnanyA function/lambda to test if the timer should continue. Return True to end the timer, False to continue it
-
actionFnanyA function/lambda to call until the predicateFn returns true
-
checkIntervalanyHow often, in seconds, to call actionFn
Return Value
None
hs.timer.doWhile
Repeat a function/lambda while a given predicate function/lambda returns true
Hammerspoon 2/Modules/hs.timer/hs.timer.js:45
Declaration
hs.timer.doWhile(predicateFn, actionFn, checkInterval) -> None
Parameters
-
predicateFnanyA function/lambda to test if the timer should continue. Return True to continue the timer, False to end it
-
actionFnanyA function/lambda to call while the predicateFn returns true
-
checkIntervalanyHow often, in seconds, to call actionFn
Return Value
None
hs.timer.waitUntil
Wait to call a function/lambda until a given predicate function/lambda returns true
Hammerspoon 2/Modules/hs.timer/hs.timer.js:71
Declaration
hs.timer.waitUntil(predicateFn, actionFn, checkInterval) -> None
Parameters
-
predicateFnanyA function/lambda to test if the actionFn should be called. Return True to call the actionFn, False to continue waiting
-
actionFnanyA function/lambda to call when the predicateFn returns true. This will only be called once and then the timer will stop.
-
checkIntervalanyHow often, in seconds, to call predicateFn
Return Value
None
hs.timer.waitWhile
Wait to call a function/lambda until a given predicate function/lambda returns false
Hammerspoon 2/Modules/hs.timer/hs.timer.js:96
Declaration
hs.timer.waitWhile(predicateFn, actionFn, checkInterval) -> None
Parameters
-
predicateFnanyA function/lambda to test if the actionFn should be called. Return False to call the actionFn, True to continue waiting
-
actionFnanyA function/lambda to call when the predicateFn returns False. This will only be called once and then the timer will stop.
-
checkIntervalanyHow often, in seconds, to call predicateFn
Return Value
None