MacOS – Command-line stop MacBook from sleeping when lid is closed

macbook promacosterminal

I've used Caffeine before and it can stop my MacBook from sleeping when the lid is closed (sometimes I want to continue listening to something through headphones while moving around)

Is there a command that can be run from the terminal that will do the same thing?

I've tried caffeinate but it does nothing. InsomniaX does stop the MacBook from sleeping when the lid is closed, is there a way to implement this same functionality from the terminal though?

Best Answer

Disable Sleeping when the lid is closed running on battery

sudo pmset -b sleep 0; sudo pmset -b disablesleep 1

Re-enable sleeping when the lid is closed running on battery

sudo pmset -b sleep 5; sudo pmset -b disablesleep 0

Remember to re-enable or manually sleep your machine before putting it into a bag. It will get very hot very quickly in an enclosed space.