I was running a script that takes ages in Terminal.

I wanted to run it unsupervised while I was working away from my MacBook, so I chose from the menu (top right) username > Login Window..., which is NOT logout, but the lock screen.

I was expecting the script to run. When I returned hours later and unlocked the screen (by typing in my password), I had to find out that while the screen was locked the script was paused all the time, and just continued where it set off when I unlocked the screen.

The expected behaviour (known from other UNIX derivatives) would have been to run while the UI was locked and secure.

How can I achieve this?

2 Answers 2


You are right that Fast User Switching (activated by clicking UsernameLogin Window… does not log you out. However it does suspend actively running applications, thus preventing intensive tasks (or even media playback) from interfering with another user’s use of your system.

What you want to do instead is lock your screen using Keychain Access.

Press ⌘ cmd space, followed by Keychain Access to launch the app. Then from the menu bar, click Keychain AccessPreferencesGeneral and check Show keychain status in menu bar.

A padlock icon will appear in the system area of your menu bar. Just click Lock Screen to lock your screen.

Lock Screen

As per @M.J.K, you may also need to prevent your Mac from going to sleep before walking away.


EDIT: With macOS High Sierra (as of beta 5) you can achieve the same "lock screen" behaviour mentioned by @Phong simply through the  status bar menu:

What I think is happening is that your computer goes to sleep after a certain amount of time after you switched to the login window which causes your script to stop.

To prevent your system from sleeping while your script is running you can run caffeinate -s in Terminal (note: only works on MacBooks if AC power is connected) or include it in your script. To stop the command hit CTRL+C.

The way I go about securing my account while I'm still logged in is to enable the "require password" option in system preferences:

require password

Then, as soon as the display (not the system) goes to sleep (also configurable in preferences) you have to enter a password in order to access the account.

You can also manually trigger display sleep by hitting CTRL+SHIFT+EJECT (if your keyboard has an eject button) or by running pmset displaysleepnow.

  • There’s a sleep button in the Apple menu, too, if that helps.
    – DonielF
    Aug 14, 2017 at 14:23
  • 2
    @DonielF Indeed, but that puts the system to sleep thus causing the script execution to stop. This can also be triggered through CMD+OPTION+EJECT
    – YourMJK
    Aug 14, 2017 at 14:40
  • That button doesn’t put the display to sleep? Good to know.
    – DonielF
    Aug 14, 2017 at 14:41
  • 2
    @DonielF Additionally to putting the system to sleep it also puts the display to sleep
    – YourMJK
    Aug 14, 2017 at 14:46

You must log in to answer this question.

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