I have a MacBook Pro running Lion. Usually, I need to run tasks that takes hours... so I just leave the laptop working before going to bed.

When I wake up, I notice that it tried to shutdown the system. How do I notice this? Well... all apps are closed except for iTerm (which always stops shutdown process when there is more than one tab open).

I tried to search the energy saving settings but there is nothing related to this... I would like to see how to prevent this behavior.

  • Related newer question that has more answers.
    – taper
    Commented Feb 10, 2018 at 10:00

2 Answers 2

  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!

  • I still found my Mac terminating process in this settings. (Thankfully the Terminal cannot be automatically terminated without user confirmation.) The caffeinated method mentioned in another answer show work better!
    – taper
    Commented Feb 10, 2018 at 9:59

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


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


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

You must log in to answer this question.

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