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?


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.


No. Only setting up closed clamshell conditions will prevent sleep when the proximity sensor indicates the lid is closed.

Short of finding a way to modify the firmware or unload / set some hidden arguments to disable sleep, the most viable solution might be hoping that power nap “dark wakes@ allow you to get whatever actions done while “sleep” conditions are present.

  • How does Caffeine/InsomniaX do it? – theonlygusti Sep 19 '17 at 10:13
  • @theonlygusti - InsomniaX doesn't seem to be working since El Cap. and newer and as far as I know Caffeine never worked with the lid (it also doesn't work now) – Allan Sep 19 '17 at 10:38
  • @Allan InsomniaX still works perfectly for me, I just tried after seeing this answer that claimed it worked. However, InsomniaX is not a perfect solution for me, I'd much rather have a way to do this from the command line without needing to install an entire application. – theonlygusti Sep 19 '17 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .