141

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.

2
  • 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 9, 2015 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, 2022 at 7:16

8 Answers 8

138
  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.

14
  • 22
    Note this is control-shift-power on newer macs without an eject key
    – dstarh
    Apr 18, 2014 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 1, 2014 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? Mar 20, 2015 at 12:53
  • 6
    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, 2016 at 11:31
  • 1
    Yes. Locking access to your device and/or keychain does not stop other processes from running.
    – mikezter
    Feb 27, 2016 at 12:44
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)

5
  • I don't appear to have this option under High Sierra. Did it move somewhere else?
    – intuited
    Jun 1, 2020 at 10:57
  • on catalina it's still there, do the hotkeys work for you?
    – wyu
    Jun 2, 2020 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 3, 2020 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 5, 2020 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 6, 2020 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

4

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!

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.

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

0
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.

You must log in to answer this question.

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