W3cubDocs

/Hammerspoon

hs.caffeinate.watcher

Watch for display and system sleep/wake/power events and for fast user switching session events.

This module is based primarily on code from the previous incarnation of Mjolnir by Steven Degutis.

API Overview

API Documentation

Constants

screensaverDidStart
Signature hs.caffeinate.watcher.screensaverDidStart
Type Constant
Description

The screensaver started

Source extensions/caffeinate/libcaffeinate_watcher.m line 42
screensaverDidStop
Signature hs.caffeinate.watcher.screensaverDidStop
Type Constant
Description

The screensaver stopped

Source extensions/caffeinate/libcaffeinate_watcher.m line 50
screensaverWillStop
Signature hs.caffeinate.watcher.screensaverWillStop
Type Constant
Description

The screensaver is about to stop

Source extensions/caffeinate/libcaffeinate_watcher.m line 46
screensDidLock
Signature hs.caffeinate.watcher.screensDidLock
Type Constant
Description

The screen was locked

Source extensions/caffeinate/libcaffeinate_watcher.m line 54
screensDidSleep
Signature hs.caffeinate.watcher.screensDidSleep
Type Constant
Description

The displays have gone to sleep

Source extensions/caffeinate/libcaffeinate_watcher.m line 26
screensDidUnlock
Signature hs.caffeinate.watcher.screensDidUnlock
Type Constant
Description

The screen was unlocked

Source extensions/caffeinate/libcaffeinate_watcher.m line 58
screensDidWake
Signature hs.caffeinate.watcher.screensDidWake
Type Constant
Description

The displays have woken from sleep

Source extensions/caffeinate/libcaffeinate_watcher.m line 30
sessionDidBecomeActive
Signature hs.caffeinate.watcher.sessionDidBecomeActive
Type Constant
Description

The session became active, due to fast user switching

Source extensions/caffeinate/libcaffeinate_watcher.m line 38
sessionDidResignActive
Signature hs.caffeinate.watcher.sessionDidResignActive
Type Constant
Description

The session is no longer active, due to fast user switching

Source extensions/caffeinate/libcaffeinate_watcher.m line 34
systemDidWake
Signature hs.caffeinate.watcher.systemDidWake
Type Constant
Description

The system woke from sleep

Source extensions/caffeinate/libcaffeinate_watcher.m line 14
systemWillPowerOff
Signature hs.caffeinate.watcher.systemWillPowerOff
Type Constant
Description

The user requested a logout or shutdown

Source extensions/caffeinate/libcaffeinate_watcher.m line 22
systemWillSleep
Signature hs.caffeinate.watcher.systemWillSleep
Type Constant
Description

The system is preparing to sleep

Source extensions/caffeinate/libcaffeinate_watcher.m line 18

Constructors

new
Signature hs.caffeinate.watcher.new(fn) -> watcher
Type Constructor
Description

Creates a watcher object for system and display sleep/wake/power events

Parameters
  • fn - A function that will be called when system/display events happen. It should accept one parameter:
    • An event type (see the constants defined above)
Returns
  • An hs.caffeinate.watcher object
Source extensions/caffeinate/libcaffeinate_watcher.m line 170

Methods

start
Signature hs.caffeinate.watcher:start()
Type Method
Description

Starts the sleep/wake watcher

Parameters
  • None
Returns
  • An hs.caffeinate.watcher object
Source extensions/caffeinate/libcaffeinate_watcher.m line 277
stop
Signature hs.caffeinate.watcher:stop()
Type Method
Description

Stops the sleep/wake watcher

Parameters
  • None
Returns
  • An hs.caffeinate.watcher object
Source extensions/caffeinate/libcaffeinate_watcher.m line 301

© 2014–2017 Hammerspoon contributors
Licensed under the MIT License.
https://www.hammerspoon.org/docs/hs.caffeinate.watcher.html