143

I want to leave my Mac awake overnight so it syncs 4GB of data from Dropbox. I need to prevent the machine from going to sleep because that pauses the Dropbox sync

I've been using Caffeine to keep the computer awake, but it also keeps the computer unlocked which is insecure.

I need a method to keep my Mac awake (so that Dropbox can sync overnight) but also locked (so no one can read my email). It'd be great if this method also turned off the screen (to preserve power), but honestly that's not even 100% necessary.

bassplayer7
  • 14,106
Tom Lehman
  • 1,795
  • 3
    In Yosemite, there is an option named *Prevent computer from sleeping automatically when the display is off" in System Preferences > Energy Saver. – Daniel Dec 09 '15 at 13:13
  • In 2022 MacOS 12.01. I succesfully used caffeinate (no special flags specified) to keep my macbook awake and locked during a whole night. I was running a crontab job every 15 minutes, yet still my screen was locked and asked me for password in the morning. – charelf Jan 12 '22 at 07:16

8 Answers8

141
  1. In System Preferences > Energy Saver, check the box for "Prevent computer from sleeping automatically when the display is off" (on laptops, this is under the Power Adapter tab)
  2. In System Preferences > Security & Privacy, check the box for "Require password after sleep or screen saver begins" and set the delay in the dropdown menu to "immediately"

Now, you can hit command+option+Q to turn off the display without sleeping the computer, and doing anything that turns on the display (like hitting a key or clicking a mouse button) will prompt you for your account password.

On older Macs, the shortcut is different: command+option+Power or control+shift+power.

Glorfindel
  • 4,057
daGUY
  • 7,813
  • 23
    Note this is control-shift-power on newer macs without an eject key – dstarh Apr 18 '14 at 17:20
  • 5
    With external keyboard without the eject key, one can check the Show keychain status in menu bar option in Keychain Access App's Preferences. Then you will be able to Lock Screen in the menu bar by clicking the lock icon. – Mengdi Gao Sep 01 '14 at 14:45
  • 3
    If I change the setting to never go to sleep, will the MacBook still go to sleep if I manually tell it to? – NobleUplift Mar 20 '15 at 12:53
  • @NobleUplift Yes, of course. – Taylor D. Edmiston Jan 03 '16 at 19:20
  • 7
    So the computer is still awake when the display is off and locked? Does it keep working when in the password prompt window? And this would apply to keeping scripts (python and php in terminal) running? – alex9311 Feb 18 '16 at 11:31
  • 1
    Yes. Locking access to your device and/or keychain does not stop other processes from running. – mikezter Feb 27 '16 at 12:44
  • 2
    Note: The Energy Saver settings are different now than when this question was answered. OS X no longer provides a way to prevent computers from sleeping while on battery power in the UI. Here is a screenshot of the current Preference pane in OS X 10.11.4: Energy Saver – jsejcksn Apr 06 '16 at 22:08
  • I have a newer Mac without an eject key, and only Command - Option - Power all pressed at exactly the same time works for me. – Jason Parker Nov 22 '16 at 12:08
  • 1
    I have MCB pro 2016 and I don't have power key. What do I do? – The Onin Feb 13 '17 at 18:28
  • 1
    So why is my download timed out with error? – powder366 Jun 17 '17 at 10:58
  • What if I used some other ways to lock the screen? Will the processes keep running? For example, I use the option lock screen from mac id to lock my screen. – zyy Feb 05 '19 at 00:12
  • Under High Sierra, I don't have a "Prevent computer from sleeping automatically when the display is off" option. There's a "Wake for network access" option but this didn't prevent the computer from sleeping last night when it was supposed to be copying a few TB of data between drives. – intuited Jun 01 '20 at 10:54
  • 1
    Both hotkeys no longer work on latest version Macbooks. Btw, when on battery, there is no way to prevent Macbook from sleeping while display is off. – xuancong84 Mar 14 '21 at 03:07
  • On my Macbook Air running Ventura, "Prevent computer from sleeping automatically when the display is off" has changed and moved to System Settings > Displays > Advanced > "Prevent automatic sleeping on power adapter when the display is off". Sounds like the mac needs to be plugged in. – Josh Harrison Dec 05 '22 at 13:26
15

Not sure when it was first available, but on MacOS High Sierra 10.13.4 you can go to Apple (top left) > Lock Screen or press control-command-q to activate the lock screen.

You should also do the first step in @daGUY's answer

In System Preferences > Energy Saver, check the box for "Prevent computer from sleeping automatically when the display is off" (on laptops, this is under the Power Adapter tab)

wyu
  • 263
  • I don't appear to have this option under High Sierra. Did it move somewhere else? – intuited Jun 01 '20 at 10:57
  • on catalina it's still there, do the hotkeys work for you? – wyu Jun 02 '20 at 19:34
  • yeah, I always lock with Command-Shift-Q but sometimes it suspends the machine—I think this happens unless there's network activity. – intuited Jun 03 '20 at 13:47
  • command shift Q logs you out, it's a different action from just showing the lock screen which is control command q.

    Also do you have "Prevent computer from sleeping automatically when the display is off" checked?

    – wyu Jun 05 '20 at 14:31
  • Wait, actually I just realized that I use CTRL-CMD-Q. I don't have that option in Preferences -> Energy Saver. – intuited Jun 06 '20 at 18:15
7

On MacOs Mojave the accepted answer didnt work for me. What worked is to use free app Amphetamine. After app installation select the option Indefinitely. Now you can lock the screen and it will not go to sleep.

enter image description here

drmaa
  • 211
5

You can use KeepingYouAwake. It is a free and lightweight menu bar utility for macOS (Version 10.10 and newer) that can prevent your Mac from entering sleep mode for a predefined duration or as long as it is activated.

It can be easily installed using Homebrew cask by running:

brew cask install keepingyouawake

It is an alternative to widely popular tool Caffeine from Lighthead Software. Caffeine hasn't been updated in a while. KeepingYouAwake's icons are Retina-compatible and do look nice in the dark themed menu bar.

Once you have activated KeepingYouAwake, you can simply lock the screen (by pressing Control + Command + q), turn down the screen brightness and remain assured that the system won't go to sleep!

Nimesh Neema
  • 51,809
3

Wimoweh will automatically keep your mac awake when user selectable processes are running and will control the display sleeping (or not) as well:

Wimoweh allows you to keep your Mac awake when any process is running - no more coming back to find your Mac has been asleep during an important job. You can optionally allow the display to sleep per process. You can set a simple timer or just keep the system awake permanently

Graham Miln
  • 43,776
3

There is no need for external utilities — you can do it using the ootb Apple command line utilities:

# prevent idle sleep while plugged in
pmset noidle

# IMPORTANT:
# COMMANDS BELOW MUST BE RUN AS ROOT 
# (prefix the command with `sudo` or get a root session 
# by typing `sudo -i` followed by your password)

# disable sleep (while plugged in or on battery)
pmset -a disablesleep 1
# after running this command you'll notice that the Sleep option
# under the Apple menu is grayed out 

# re-enable sleep
pmset -a disablesleep 0

# prevent sleep for 1 hour while on battery (this must be run under a root session with `sudo -i`)
pmset -a disablesleep 1 && sleep 3600 && pmset -a disablesleep 0

❗️❗️❗️ WARNING: After you disable sleep with sudo pmset -a disablesleep 1 your mac will stop sleeping and the Sleep option under the apple menu will stay greyed out even after a reboot and even on battery power. You MUST run sudo pmset -a disablesleep 0 if you want to restore normal sleep.

For more usage info use man pmset and man caffeinate in your terminal. Keep in mind that caffeinate only works when running on AC power.

ccpizza
  • 2,995
  • 3
  • 36
  • 41
2

If you don't use an Apple keyboard, you can lock it with the mouse by selecting your name in the right-side of the menubar and click Login Window...

-1

You can try "Lock Me Now" app from the app store. It gives a pretty neat way to lock the mac.