Keep your MacBook awake with the lid closed — with a menu bar indicator, one-click toggle, and a battery guard so it never drains to zero.
macOS normally sleeps a MacBook the moment you close the lid (unless an external display is connected). lid-toggle flips that with one click, and shows the current state in your menu bar at all times:
- ☕ ON — Mac stays awake with the lid closed
- 💤 OFF — normal sleep behavior
- One-command toggle (
lidtoggle) with a macOS notification on every switch - Always-visible menu bar indicator via SwiftBar — click it to toggle
- Battery guard: if you're on battery and drop to ≤25%, normal sleep is automatically re-enabled (with a notification) so a forgotten toggle can't kill your battery
- No password prompts after setup (scoped sudoers rule for
pmsetonly) - Plain bash, no daemons, no background processes of its own
git clone https://github.com/KevinBolcic/lid-toggle.git
cd lid-toggle
./install.shThe installer:
- Copies
lidtoggleto~/bin/ - Adds
/etc/sudoers.d/pmsetsopmsetruns without a password prompt (validated withvisudobefore installing; asks for your password once) - Optionally installs SwiftBar (via Homebrew) and the menu bar plugin, and adds SwiftBar to your login items
- Click the ☕/💤 icon in the menu bar → Toggle
- Or run
~/bin/lidtogglein a terminal - Or wire it to a Shortcuts shortcut / desktop widget that runs
~/bin/lidtogglevia "Run Shell Script"
Check the raw state anytime:
pmset -g | grep SleepDisabled # 1 = stays awake, 0 = normalThe toggle is just sudo pmset -a disablesleep 1|0. The SwiftBar plugin (lid.1m.sh) re-reads the state every minute, renders the icon, and enforces the battery guard. The toggle script pings SwiftBar (swiftbar://refreshallplugins) so the icon updates instantly rather than waiting for the next refresh.
sudo pmset -a disablesleep 0 # restore normal sleep
rm ~/bin/lidtoggle
sudo rm /etc/sudoers.d/pmset
rm "$(defaults read com.ameba.SwiftBar PluginDirectory)/lid.1m.sh"Remove SwiftBar too if you installed it only for this: brew uninstall --cask swiftbar.
- The battery guard runs inside the SwiftBar plugin, so it's only active while SwiftBar is running (it's added as a login item, so in practice: always).
disablesleepkeeps the machine fully awake — this is intentionally stronger thancaffeinate, and uses more battery. That's what the guard is for.- Tested on Apple Silicon MacBooks, macOS Sonoma and later.