Found no links on internet where someone was able to make it happen. Most answers go round and round without providing a working solution. I'm starting to believe that this is not possible on a Mac.


I have some scripts that runs tests, build code etc. I want to be able to start the script and "lock" my machine and go home for the day, while the tests continue running behind the locked screen.

However, the moment the screen is locked, the terminal processes just pause. They continue again as soon as I log back in. So the machine just stays powered on the whole night, doing nothing.

Is there a way to be able to run my scripts with locked screen. Note that I'm only locking the screen (control + command + Q) and not even logging out (shift + command + Q). However, the moment the screen is locks out, the tests simply pause.

Most likely this is a safety thing implemented to prevent the machine from not running out of the battery in case there is a power outage. Is there a way I can get around this?

  • What kinds of scripts are these? Are they shell scripts, AppleScripts, etc? The reason that I ask is if they are using System Events or otherwise manipulating apps in some kind of automated fashion, that may not be possible with the screen locked. Apple may consider this a security feature. I'm not sure that's the issue, but it's a possibility.
    – TJ Luoma
    Commented Oct 17, 2019 at 18:50
  • @TJLuoma: Yes they are shell scripts that start a program, call it for a test, shut the program. Commented Oct 17, 2019 at 19:01
  • It's no problem to run shell scripts or commands as a user (more or less with the user's env!) even after logging out (tested in 10.11). This works with the at feature. I think it's indeed a problem with your power savings settings. Would you mind adding them to your question (pmset -g) and also your macOS version.
    – klanomath
    Commented Oct 17, 2019 at 22:41

2 Answers 2


I believe that this has something to do with power savings settings. There is slider for "Turn display off after:" and by default "Prevent computer from sleeping automatically when the display is off" option is not selected.

Maybe caffeinate can help (prevent the system from sleeping on behalf of a utility). 'man caffeinate' for more information.

  • 2
    I'm sure power settings thing doesn't work. That is what I tinkered with for so long already. Trying caffeinate though. It looks promising. Commented Oct 17, 2019 at 18:17

For me, this is a working solution:

  • Check power settings, don't go to sleep / Don't turn off display
  • Start "caffeinate" or "amphetamine app"
  • Enable "Ask for password on screensaver immediately" in System preferences → Safety
  • Start your command
  • Start your screensaver

Your screen is locked, but the command is still executing.

You can start your screensaver with a better touch tool action or a keyboard shortcut with automator.

You must log in to answer this question.

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