Skip to content
/ wake Public

Script to prevent Macbook from sleeping when lid is closed

License

Notifications You must be signed in to change notification settings

Moarram/wake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 

Repository files navigation

wake

Macbooks sleep when the lid is closed (unless plugged in to an external monitor). To keep the Macbook awake we can use pmset disablesleep.

I made a convenience script wake.sh that disables sleep and automatically re-enables it when quit.


pmset disablesleep

The pmset man pages have no mention of disablesleep but it does in fact disable sleep, even with a closed lid.

WARNING: The Macbook has reduced cooling ability while the lid is closed and could overheat in a confined space (such as a backpack).

Disable sleep

sudo pmset disablesleep 1

Enable sleep (default)

sudo pmset disablesleep 0

wake.sh

The script simply wraps the above commands. It will disable sleep while running and re-enable when quit.

Give executable permissions

The script needs executable permission

chmod +x wake.sh

Usage

Run it to disable sleep

sudo ./wake.sh

Press any key or quit the script to re-enable sleep

Make script global (optional)

If you want to run the script from anywhere as a command, add it to /usr/local/bin with a link

sudo ln -s /your/absolute/path/to/wake.sh /usr/local/bin/wake

Run it anywhere

sudo wake

Remove password requirement (optional)

The power management command pmset requires sudo to run. If you don't want to enter your password each time you can remove the password requirement for your user.

WARNING: Do this at your own risk as it obviously reduces security.

  1. Open the sudo configuration editor in your terminal with sudo visudo
  2. Add to the end of the file <user> ALL=(ALL) NOPASSWD: /usr/bin/pmset where <user> is your username
  3. Save changes with :wq

Run it without password

wake

About

Script to prevent Macbook from sleeping when lid is closed

Resources

License

Stars

Watchers

Forks

Languages