Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lid-toggle

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.

lid-toggle in the menu bar

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

Features

  • 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 pmset only)
  • Plain bash, no daemons, no background processes of its own

Install

git clone https://github.com/KevinBolcic/lid-toggle.git
cd lid-toggle
./install.sh

The installer:

  1. Copies lidtoggle to ~/bin/
  2. Adds /etc/sudoers.d/pmset so pmset runs without a password prompt (validated with visudo before installing; asks for your password once)
  3. Optionally installs SwiftBar (via Homebrew) and the menu bar plugin, and adds SwiftBar to your login items

Usage

  • Click the ☕/💤 icon in the menu bar → Toggle
  • Or run ~/bin/lidtoggle in a terminal
  • Or wire it to a Shortcuts shortcut / desktop widget that runs ~/bin/lidtoggle via "Run Shell Script"

Check the raw state anytime:

pmset -g | grep SleepDisabled   # 1 = stays awake, 0 = normal

How it works

The 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.

Uninstall

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.

Caveats

  • 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).
  • disablesleep keeps the machine fully awake — this is intentionally stronger than caffeinate, and uses more battery. That's what the guard is for.
  • Tested on Apple Silicon MacBooks, macOS Sonoma and later.

License

MIT

About

Keep your MacBook awake with the lid closed — menu bar toggle (SwiftBar) with a low-battery auto-off guard

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages