Skip to content

RyanNg1403/lidwake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

lidwake

A small CLI that keeps a Mac awake with the lid closed — so background work (long-running scripts, remote shells, AI agents) can keep running while the laptop is in a bag.

No kernel extension, no GUI app, no third-party daemon. Just a single Python file wrapping pmset and caffeinate.

Why

By default, macOS only stays awake in clamshell (lid-closed) mode when both AC power and an external display are attached. On battery alone, closing the lid puts the machine to sleep. Existing workarounds either need a paid GUI app (Amphetamine + Enhancer) or an unmaintained kernel extension. This is a 280-line shell-friendly alternative.

How it works

  • sudo pmset -a disablesleep 1 — disables the lid-close sleep trigger
  • caffeinate -dimsu — prevents idle, display, system, and disk sleep
  • Optional background watcher to auto-revert after a duration or when a target process exits

State lives in ~/.lidwake/state.json and is restored on lidwake off.

Install

Requires macOS and Python 3.9+ (uses only the standard library).

git clone https://github.com/RyanNg1403/lidwake.git
cd lidwake
./lidwake install     # copies to /usr/local/bin/lidwake (one sudo prompt)

Optional, to skip the password on every toggle:

lidwake trust         # installs a sudoers.d rule scoped to ONLY:
                      #   pmset -a disablesleep 0
                      #   pmset -a disablesleep 1
lidwake untrust       # revoke

Usage

lidwake on                    # indefinite — stays awake until you run 'off'
lidwake on 2h                 # auto-off after 2 hours
lidwake on 30m                # auto-off after 30 minutes
lidwake on 1h30m              # mixed durations
lidwake on --while claude     # auto-off when the 'claude' process exits
lidwake on 4h --while claude  # whichever comes first

lidwake off                   # restore default sleep behavior
lidwake status                # show pmset state, mode, time left, watched process

Commands

Command Effect
on [DURATION] [--while NAME] Enable lid-closed wake. Optional auto-off conditions.
off Restore default sleep behavior.
status Show current state.
trust Install a scoped sudoers rule for passwordless toggling.
untrust Remove the sudoers rule.
install Copy this script to /usr/local/bin/lidwake.
uninstall Remove the script, sudoers rule, and state directory.

Caveats

  • Heat. A running MacBook sealed in a backpack has almost no airflow. Expect thermal throttling within minutes; on a hot day the SMC may force-shutdown. A mesh sleeve helps; a padded zipped pocket does not.
  • Battery. An active workload with the lid closed drains 2–4× faster than idle. Plan accordingly.
  • pmset -a, not -b. The setting applies to both AC and battery. If you want to enforce sleep when plugged in, file an issue.
  • Apple Silicon. Works on M-series. No kext, no SIP changes, no reduced-security mode required.

Uninstall

lidwake uninstall     # removes the script, sudoers rule, and ~/.lidwake/

License

MIT

About

Keep a Mac awake with the lid closed. Pure pmset + caffeinate, no kext, no GUI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages