hammerspoon2-docs
    Preparing search index...

    Namespace power

    Monitor and control system power: prevent sleep, read battery state, respond to power events, and lock or sleep the machine.

    // Prevent the display from sleeping while a task runs
    hs.power.preventSleep("display")
    // ... do work ...
    hs.power.allowSleep("display")
    hs.power.addEventWatcher(event => {
    if (event === "screensDidLock") console.log("Screen locked!")
    })
    const info = hs.power.batteryInfo()
    if (info) {
    console.log(`Battery: ${info.percentage}%, ${info.timeRemaining} minutes remaining`)
    }

    Variables

    isCharging
    isLowPowerMode
    percentage
    powerSource
    thermalState

    Functions

    addBatteryWatcher
    addEventWatcher
    allowSleep
    batteryInfo
    currentAssertions
    declareActivity
    isSleepPrevented
    lockScreen
    preventSleep
    removeBatteryWatcher
    removeEventWatcher
    startScreensaver
    systemSleep