Keep your MacBook working while the lid is closed — toggle macOS clamshell mode with one click or one command.
By default, macOS sleeps when you close the lid (unless an external display + power + keyboard are attached). If you run long background jobs — training runs, agents, builds, downloads — closing the lid kills them. This flips Apple's hidden pmset disablesleep switch so your Mac keeps running with the lid shut, then flips it back when you're done.
💡 Pro tip: Set your display brightness to 0 before you close the lid. Otherwise the internal display stays lit the whole time behind the closed lid, wasting power and generating heat.
curl -fsSL https://raw.githubusercontent.com/Magister2k/mac-clamshell-toggle/main/install.sh | bashDuring install you choose how toggling works:
- With password (default) — macOS asks for your admin password each time. Nothing is changed on your system.
- Without password — adds a single, tightly-scoped
sudoersrule (onlypmset -a disablesleep 0/1) so you can toggle with one click, no prompt.
The installer also builds the menu-bar app SchlafToggle.app if Xcode Command Line Tools are present.
clamshell-toggle # toggle (awake <-> sleep allowed)
clamshell-toggle on # force stay-awake (works with lid closed)
clamshell-toggle off # allow sleep again
clamshell-toggle status # show current stateOpen SchlafToggle.app (in ~/Applications). A small icon appears in your menu bar:
- ☕
cup.and.saucer→ Mac stays awake (lid can be closed) - 💤
moon.zzz→ sleep allowed
Click it to toggle.
It's a thin wrapper around a built-in macOS command:
sudo pmset -a disablesleep 1 # stay awake, even with lid closed
sudo pmset -a disablesleep 0 # back to normalCheck the state yourself anytime with pmset -g | grep SleepDisabled.
The tool tries sudo -n pmset … first (passwordless mode); if that isn't set up, it falls back to a GUI admin-password prompt.
git clone https://github.com/Magister2k/mac-clamshell-toggle.git
cd mac-clamshell-toggle
swiftc -O src/SchlafToggle.swift -o SchlafToggle # the menu-bar app binary
# or just use the CLI:
chmod +x clamshell-toggle.sh && ./clamshell-toggle.sh statusThe app is unsigned. On first launch macOS Gatekeeper may warn you — right-click → Open, or xattr -dr com.apple.quarantine ~/Applications/SchlafToggle.app.
rm ~/.local/bin/clamshell-toggle
rm -rf ~/Applications/SchlafToggle.app
sudo rm -f /etc/sudoers.d/clamshell-toggle # only if you chose passwordless mode- Requires macOS 12+ on Apple Silicon or Intel.
disablesleepkeeps the whole system awake, not just the display — that's the point, but it also means the Mac won't sleep on battery until you toggle off. Watch your battery.- This does not disable thermal protection. A closed lid reduces airflow; keep an eye on temperatures during heavy loads.
This is the very first version (v0.1). It works, but it's early — ideas, bug reports and change requests are very welcome! Open an issue or send a pull request and I'll take a look.
🇩🇪 Das ist die allererste Version. Schickt mir gerne eure Änderungswünsche, Bugs oder Ideen als Issue oder Pull Request — ich freue mich über Feedback!
Open source under the MIT License — free to use, modify and share. See LICENSE.
v0.1 — German UI strings, English docs.