Skip to content

shamrai-nikita/StayAwake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

StayAwake

StayAwake

Keep your Mac awake — even with the lid closed.

Built so your background agents, training jobs, and long-running tasks don't die when you walk away.

Install · Uninstall · How it works


Why this exists

macOS aggressively sleeps when you close the lid. That's a problem if you rely on background work continuing — Claude Code agents, long builds, model downloads, syncing, rsync jobs, training runs.

Apple's own Power Mode and tools like Caffeine don't actually defeat clamshell sleep. The only reliable knob is pmset disablesleep 1, which requires sudo. StayAwake wraps that one toggle in a clean menu bar app so you can enable/disable it like any other utility — no terminals, no sticky notes with passwords.

Close the lid. Walk away. Your agents keep running.


Features

  • 🔥 Closed-lid mode that actually works — uses pmset disablesleep, the only macOS API that defeats clamshell sleep
  • 🖥️ Display stays on too — useful if you VNC/Screen-Share into the machine while away
  • ⏱️ Caffeine-style timer — activate for 5 / 15 / 30 min, 1 / 2 / 5 h, or indefinitely; auto-disables silently when it expires
  • 👆 Optional Touch ID gate — off by default for a friction-free toggle; turn it on if you want a confirmation prompt before each manual change
  • 🍎 Menu bar only — no Dock icon, no window unless you want one
  • 🚀 Launch at login + optional auto-activate on launch
  • 🧹 Clean uninstall — one button removes the app, the helper rule, and all preferences
  • 📦 Tiny — single Swift binary, no external dependencies, ~200 KB built

Screenshots

Inactive Active
Inactive menu bar icon Active menu bar icon
System sleep allowed System sleep prevented

Right-click menu with Activate-for submenu
Right-click → Activate for sets a timer. The icon auto-disables silently when it expires.

Preferences window


Install

From source

Requires macOS 13+ on Apple Silicon and Xcode Command Line Tools (xcode-select --install).

git clone https://github.com/shamrai-nikita/StayAwake.git
cd StayAwake
make install

That copies StayAwake.app to /Applications and launches it. On first run it offers to install a passwordless pmset helper at /etc/sudoers.d/stayawake — that one-time admin prompt is the only password you'll ever type.


Usage

  • Left-click the menu bar icon → toggle sleep prevention on/off
    • 🟧 colorful eye = sleep prevented
    • ⚪ outline eye = sleep allowed
  • Right-click the menu bar icon → contextual menu:
    • Activate / Disable — indefinite toggle
    • Activate for ▸ — 5 / 15 / 30 min, 1 / 2 / 5 h, or Indefinitely
    • Active until … + Cancel timer — shown only while a timer is running
    • Preferences… / Quit
  • The Preferences window has:
    • A big Activate / Disable button
    • Timer — pick a duration and click Activate; the active-until time + a Cancel timer button appear while one is running
    • Startup — Launch at login, Prevent sleep on launch
    • SecurityRequire Touch ID to toggle (off by default; timer expiry is always silent)
    • Uninstall StayAwake… (see below)

Uninstall

Open Preferences and click Uninstall StayAwake… at the bottom. It will:

  1. Re-enable system sleep (pmset -a disablesleep 0)
  2. Remove the Touch ID helper (/etc/sudoers.d/stayawake)
  3. Remove StayAwake.app from /Applications
  4. Disable launch-at-login
  5. Clear all StayAwake preferences

You'll be asked for your admin password once, and the app will quit immediately after.

If you'd rather do it manually:

sudo pmset -a disablesleep 0
sudo rm -f /etc/sudoers.d/stayawake
rm -rf /Applications/StayAwake.app
defaults delete com.nikitash.stayawake

How it works

Layer What it uses
Sleep prevention pmset -a disablesleep 1/0 invoked via sudo (no password thanks to the helper rule)
Auth gate Off by default. When enabled, LAContext.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics) — Touch ID required for manual toggles. Timer auto-expiry never prompts.
Timer DispatchSourceTimer on the main queue; on fire, runs the silent pmset path and broadcasts a NotificationCenter state change to the menu and Preferences UI.
Menu bar NSStatusItem with custom NSImage rendered from PNG assets (chroma-keyed black background → transparent)
Login item SMAppService.mainApp (macOS 13+)
Bundling Plain swiftc + iconutil, packaged into a .app directory by a Makefile — no Xcode project, no SwiftPM

Project layout

StayAwake/
├── Sources/
│   ├── main.swift                       — entry point
│   ├── AppDelegate.swift                — wires managers together
│   ├── SleepManager.swift               — pmset toggle + Touch ID
│   ├── StatusBarManager.swift           — menu bar icon + click dispatch
│   ├── LoginItemManager.swift           — SMAppService wrapper
│   ├── PreferencesWindowController.swift — settings window (no nib)
│   ├── HelperInstaller.swift            — first-run sudoers helper install
│   └── Icons.swift                      — PNG → menu-bar NSImage pipeline
├── Resources/
│   ├── Info.plist                       — LSUIElement=YES (menu-bar-only)
│   ├── AppIcon.png                      — source for the .icns
│   ├── MenuBarEye.png                   — active state (color)
│   └── MenuBarEyeOutline.png            — inactive state (template)
├── tools/
│   └── generate_icon.swift              — auto-crops & renders the iconset
└── Makefile                             — build / install / clean / run

Security notes

  • The sudoers rule grants passwordless sudo only for /usr/bin/pmset. It cannot be used to escalate to anything else.
  • Manual toggles are silent by default. Anyone at your unlocked Mac can flip the state — if that matters to you, turn on Require Touch ID in Preferences → Security and you'll be prompted for biometrics on every manual change.
  • Timer expiry is always silent (a Touch ID prompt would just hang if you've walked away from the keyboard). The duration you set is the consent.
  • The app is locally codesigned (codesign --sign -) — Gatekeeper will warn the first time you open it. Right-click → Open to allow.
  • No telemetry, no network calls, no analytics. The app never touches the network.

License

MIT — see LICENSE.

About

macOS menu bar app that keeps your Mac awake — even with the lid closed. Built so background agents and long-running tasks don't die when you walk away.

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors