MacOS – way for locking the screen and putting it to sleep/activating the screen saver to be two different events on a MBP

displaymacbook promacosscreensaversleep-wake

This question is very similar to what I want to accomplish, except for the fact that I also want to be able to put the display to sleep at times without triggering it to ask me for a password. I basically want to be able to do two things:

  • At times, lock the screen, much like I do in a PC by hitting Win+L. I'm fine with the screen going to sleep at this time, and if this step was all I wanted, hitting control+shift+power would do the trick if Require password [amount of time] after sleep or screen saver begins under System Preferences > Security was checked. However;
  • I also want to be able to, sometimes, just put the display to sleep or let it eventually start the screen saver without it asking for a password afterwards. I could also accomplish this one simply, if I unchecked Require password [amount of time] after sleep or screen saver begins under System Preferences > Security, but again that would make me unable to do what I wanted to do above.

I can do this all in Windows by enabling the screen saver, and not checking the box that specifies that it'd get me to the login screen when on resume. That way, I can let the screen saver get triggered and the display eventually go to sleep and it won't ask me for a password when I resume; and I can also simply lock the session when I want to by hitting Win+L, and then the display will eventually go to sleep.

Is this possible to accomplish in a Mac?

Best Answer

There are a number of posts (here and here) on superuser.sx.

  • To lock the screen (actually invoking the "Login Window…" action from the User menu, and a direct analog to the Win+L shortcut in Windows):

    /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
    
  • To sleep the display (I use this all the time as part of my last command before bedtime on my home machine):

    pmset displaysleepnow
    

Either of these options can be invoked through a keyboard shortcut by tying a shell script to a shortcut (using Automator (like this), Quicksilver, LaunchBar, Alfred, etc., see this post).

It's worth noting that BetterTouchTool can also perform these actions (directly mapping shortcuts to actions like this), as noted in this answer to one of the prior questions). The developer has been giving the app some love recently, which has been wonderful to see.