☾ SleepToggle · how it works

How SleepToggle works

You're being asked to pipe a script into bash and type your sudo password. Here is the complete list of what that does — and why it's built this way.

The app itself

SleepToggle is a single Swift file — about 100 lines, AppKit only, no dependencies: read it here. It puts an icon in the menu bar (☾ normal sleep, ☕ sleep disabled), and clicking the menu item runs one of two commands:

sudo pmset -a disablesleep 1   # ☕ stay awake, even with the lid closed
sudo pmset -a disablesleep 0   # ☾ normal sleep

The icon re-reads the real state from pmset -g every time you open the menu and once a minute, so it stays truthful even if you change the setting from Terminal. Why this setting beats the usual approach is covered in lid-closed sleep, explained.

Everything the installer touches

  1. ~/Applications/SleepToggle.appthe installer downloads the source and compiles it on your Mac with Apple's own tools. There is no prebuilt binary: what runs is exactly what you can read, and a locally-built app needs no App Store, no code signing and no Gatekeeper exceptions.
  2. /etc/sudoers.d/pmset-disablesleep — one line letting your user run exactly pmset -a disablesleep 1 and pmset -a disablesleep 0 without a password. Nothing else gains sudo. This is the only reason the installer asks for your password, and the rule is validated with visudo before it's installed.
  3. ~/Library/LaunchAgents/com.sleeptoggle.plist — starts the app at login. macOS shows its standard "can run in the background" notice once; you can manage it in System Settings → Login Items.

Requirements: macOS 11 or newer, and Apple's Command Line Tools (the installer opens Apple's own dialog if they're missing).

What it doesn't do

Uninstall

curl -fsSL https://sleep.138.dk/uninstall.sh | bash

Removes all three pieces above and re-enables normal sleep. Read it first if you like. Nothing is left behind.