On this page
hs.timer
Execute functions with various timing rules
NOTE: timers use NSTimer internally, which will be paused when computers sleep. Especially, repeating timers won't be triggered at the specified time when there are sleeps in between. The workaround is to prevent system from sleeping, configured in Energy Saver in System Preferences.
Submodules
API Overview
- Functions - API calls offered directly by the extension
- Constructors - API calls which return an object, typically one that offers API methods
- Methods - API calls which can only be made on an object returned by a constructor
API Documentation
Functions
absoluteTime
Signature | hs.timer.absoluteTime() -> nanoseconds |
---|---|
Type | Function |
Description | Returns the absolute time in nanoseconds since the last system boot. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 447 |
days
Signature | hs.timer.days(n) -> sec |
---|---|
Type | Function |
Description | Converts days to seconds |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 81 |
hours
Signature | hs.timer.hours(n) -> seconds |
---|---|
Type | Function |
Description | Converts hours to seconds |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 70 |
localTime
Signature | hs.timer.localTime() -> number |
---|---|
Type | Function |
Description | Returns the number of seconds since local time midnight |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 215 |
minutes
Signature | hs.timer.minutes(n) -> seconds |
---|---|
Type | Function |
Description | Converts minutes to seconds |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 59 |
seconds
Signature | hs.timer.seconds(timeOrDuration) -> seconds |
---|---|
Type | Function |
Description | Converts a string with a time of day or a duration into number of seconds |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 45 |
secondsSinceEpoch
Signature | hs.timer.secondsSinceEpoch() -> sec |
---|---|
Type | Function |
Description | Gets the (fractional) number of seconds since the UNIX epoch (January 1, 1970) |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 424 |
usleep
Signature | hs.timer.usleep(microsecs) |
---|---|
Type | Function |
Description | Blocks Lua execution for the specified time |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 243 |
weeks
Signature | hs.timer.weeks(n) -> sec |
---|---|
Type | Function |
Description | Converts weeks to seconds |
Parameters |
|
Returns |
|
Source | extensions/timer/timer.lua line 92 |
Constructors
doAfter
Signature | hs.timer.doAfter(sec, fn) -> timer |
---|---|
Type | Constructor |
Description | Calls a function after a delay |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 205 |
doAt
Signature | hs.timer.doAt(time[, repeatInterval], fn[, continueOnError]) -> timer |
---|---|
Type | Constructor |
Description | Creates and starts a timer which will perform |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 229 |
doEvery
Signature | hs.timer.doEvery(interval, fn) -> timer |
---|---|
Type | Constructor |
Description | Repeats fn every interval seconds. |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 159 |
doUntil
Signature | hs.timer.doUntil(predicateFn, actionFn[, checkInterval]) -> timer |
---|---|
Type | Constructor |
Description | Creates and starts a timer which will perform |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 131 |
doWhile
Signature | hs.timer.doWhile(predicateFn, actionFn[, checkInterval]) -> timer |
---|---|
Type | Constructor |
Description | Creates and starts a timer which will perform |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 195 |
new
Signature | hs.timer.new(interval, fn [, continueOnError]) -> timer |
---|---|
Type | Constructor |
Description | Creates a new |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 128 |
waitUntil
Signature | hs.timer.waitUntil(predicateFn, actionFn[, checkInterval]) -> timer |
---|---|
Type | Constructor |
Description | Creates and starts a timer which will perform |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 103 |
waitWhile
Signature | hs.timer.waitWhile(predicateFn, actionFn[, checkInterval]) -> timer |
---|---|
Type | Constructor |
Description | Creates and starts a timer which will perform |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/timer.lua line 176 |
Methods
fire
Signature | hs.timer:fire() -> timer |
---|---|
Type | Method |
Description | Immediately fires a timer |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 336 |
nextTrigger
Signature | hs.timer:nextTrigger() -> number |
---|---|
Type | Method |
Description | Returns the number of seconds until the timer will next trigger |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 283 |
running
Signature | hs.timer:running() -> boolean |
---|---|
Type | Method |
Description | Returns a boolean indicating whether or not the timer is currently running. |
Parameters |
|
Returns |
|
Source | extensions/timer/libtimer.m line 264 |
setNextTrigger
Signature | hs.timer:setNextTrigger(seconds) -> timer |
---|---|
Type | Method |
Description | Sets the next trigger time of a timer |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 307 |
start
Signature | hs.timer:start() -> timer |
---|---|
Type | Method |
Description | Starts an |
Parameters |
|
Returns |
|
Notes |
|
Source | extensions/timer/libtimer.m line 179 |
stop
Signature | hs.timer:stop() -> timer |
---|---|
Type | Method |
Description | Stops an |
Parameters |
|
Returns |
|
Source | extensions/timer/libtimer.m line 359 |
© 2014–2017 Hammerspoon contributors
Licensed under the MIT License.
https://www.hammerspoon.org/docs/hs.timer.html