Skip to content

Magister2k/mac-clamshell-toggle

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mac-clamshell-toggle

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.


Install (one command)

curl -fsSL https://raw.githubusercontent.com/Magister2k/mac-clamshell-toggle/main/install.sh | bash

During 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 sudoers rule (only pmset -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.


Usage

CLI

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 state

Menu-bar app

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


How it works

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 normal

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


Build from source

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 status

The app is unsigned. On first launch macOS Gatekeeper may warn you — right-click → Open, or xattr -dr com.apple.quarantine ~/Applications/SchlafToggle.app.


Uninstall

rm ~/.local/bin/clamshell-toggle
rm -rf ~/Applications/SchlafToggle.app
sudo rm -f /etc/sudoers.d/clamshell-toggle   # only if you chose passwordless mode

Notes & caveats

  • Requires macOS 12+ on Apple Silicon or Intel.
  • disablesleep keeps 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.

Contributing & feedback

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!

License

Open source under the MIT License — free to use, modify and share. See LICENSE.


v0.1 — German UI strings, English docs.

About

Keep your MacBook working with the lid closed — toggle macOS clamshell mode (pmset disablesleep) via CLI or menu-bar app.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors