MacOS/How To/Keep a Mac Awake with the Lid Closed
Properties
- tags
- Diataxis/How To
- logseq-entity
- Logseq/Entity/Diataxis/How To
- see-also
- pmset, CaffeinateCLI
How To Keep a Mac Awake with the Lid Closed
Overview
- Keep a MacBook running with its lid closed, for example while a render or an agent session finishes, then put lid-close sleep back the way it was.
- The switch is the pmset setting
disablesleep. CaffeinateCLI holds off idle sleep but does not keep the Mac awake through a lid close.
Prerequisites
- The
pmset:lid-awake:*tasks from Person/codekiln/GitHub/dotfiles, applied withchezmoi apply. They were added in codekiln/dotfiles#173 Keep the Mac awake with the lid closed and restore it. - An admin account, for the one
sudoprompt in step 1.
- The
Steps
1. Allow the switch without a password
- If you want to skip the password prompt, install the sudoers rule once. It covers only
pmset -a disablesleep 1andpmset -a disablesleep 0for your user. - sh
mise run pmset:lid-awake:install-sudoers - If you skip this step, each switch asks for your password, or for Touch ID if
pam_tid.sois enabled in/etc/pam.d/sudo_local.
- If you want to skip the password prompt, install the sudoers rule once. It covers only
2. Turn lid-close sleep off
3. Close the lid
4. Put lid-close sleep back
Troubleshooting
- To check the current state, run
pmset -g | grep SleepDisabled.1means the Mac stays awake with the lid closed. - If the Mac still sleeps when the lid closes, run
pmset -gand look forSleepDisabled 1. If it reads0, run step 2 again. - If
install-sudoerssays there is no TTY, run it in a terminal yourself. It needs to ask for your password once. - To return to a password prompt on every switch, run
mise run pmset:lid-awake:install-sudoers --remove.
- To check the current state, run