Skip to content

Conversation

@Loxed
Copy link

@Loxed Loxed commented Jul 1, 2025

Add LowPowerToggle Spoon for automatic Low Power Mode toggling based on user idle state

Description

This PR adds a new Spoon called LowPowerToggle that automatically enables macOS Low Power Mode after a configurable period of user inactivity, and disables it immediately upon user activity.

Motivation

I run my Mac Mini as a 24/7 always-on machine, which I connect to remotely via Parsec. Since it spends a lot of time idle, I wanted an automatic way to toggle Low Power Mode to save energy without manually switching it on and off.

This Spoon uses Hammerspoon’s eventtap to efficiently detect user input events in real-time — avoiding inefficient polling — to toggle Low Power Mode seamlessly.

Features

  • Monitors keyboard and mouse events in real-time using Hammerspoon’s eventtap.
  • Enables Low Power Mode (pmset -a lowpowermode 1) after a default idle timeout of 5 minutes.
  • Disables Low Power Mode (pmset -a lowpowermode 0) instantly when user input is detected.
  • Displays macOS notifications when the power mode toggles.
  • Includes a helper script to safely add the necessary sudoers rule for passwordless pmset execution.
  • Configurable idle timeout via the idleThreshold variable in init.lua.

Requirements

  • macOS 12.3 or later (with Low Power Mode support).
  • Hammerspoon installed.
  • pmset requires sudo privileges; users should configure passwordless sudo for the two pmset commands as documented.

Installation

  1. Place LowPowerToggle.spoon in the Spoons directory.

  2. Run the included script to allow passwordless sudo for pmset (required for toggling Low Power Mode):

sudo bash add_pmset_to_sudo.sh
  1. Load and start the Spoon from your ~/.hammerspoon/init.lua:
local lowPowerToggle = hs.loadSpoon("LowPowerToggle")
lowPowerToggle:start()

Reload your Hammerspoon config (via menu or hs.reload()).

Notes

  • The README provides detailed instructions on setup and usage.
  • The Spoon has been tested on macOS Sequoia 15.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant