Avoid automatic shutdown

  1. Make sure your power adapter is connected to the Mac while you are sleeping.

  2. In the Power Adapter section in Energy Saver, make the "computer sleep" -> "never".

  3. You don't want your screen is on when you are in bed right? So make "Display sleep" -> some minutes.

  4. Uncheck "Put the hard disk(s) to sleep when possible" and "Restart automatically if the computer freezes".

That should work!


You can also temporarily disable sleep from the command line with "caffeinate" regardless of the sleep settings in system preferences.

caffeinate

The basic function of caffeinate when run without any arguments it to prevent active sleep while caffeinate is running:

caffeinate

It will prevent active sleep until you stop caffeinate with "Control + C" or kill all caffeinate processes. After termination the MacBook will resume its normal behaviour (perfect for a computational intensive task)

You can also run caffeinate for a specific pre-determined amount of time to prevent sleeping for that specific amount of time e.g. 4 hours (specify time in seconds) - The ampersand makes the terminal run the process in the background so you continue working.

caffeinate -t 144000 &

Caffeinate can also be attached to other commands to prevent the MacBook from sleeping while the given command is being executed:

caffeinate [command_to_run] -arguments

For a full list of options please refer to the man-page