GitHub - KristijanKocev/lidwatch: Sleep a docked MacBook when its lid closes

2 min read Original article ↗

LidWatch listens to the lid state of your laptop and does not allow the default clamshell behaviour where external displays stay awake if connected to a power source. After looking for an easy solution, I tried noclamshell but I didn't like the approach it took where it basically polled every 2 seconds and reacted to the lid state at the time of the poll. This + using a stale state reading led to a bug where it activated sleep mode with the lid open. I also did not want to install an app as I see this as a lightweight utility your turn on and forget, not something taking up menu bar space.

The way it works is by listening to native macOS state for power, external displays and the lid position, resulting in a noop if no power of external display is connected or sending the external display to sleep if all conditions are met.

Install

curl -fsSL https://raw.githubusercontent.com/KristijanKocev/lidwatch/main/install.sh | bash

Or install it with Homebrew:

brew tap KristijanKocev/tap
brew install lidwatch
brew services start lidwatch

Service

brew services start lidwatch
brew services stop lidwatch
brew services restart lidwatch

brew services start starts LidWatch immediately and again at every login.

Build from source

The executable is written to .build/release/LidWatch.

Test

The policy tests and fuzzer do not link the system-sleep implementation.

brew install llvm@20
swift test
scripts/fuzz.sh 1000000

The fuzz iteration count is optional and defaults to one million. The fuzzer requires Homebrew llvm@20.