How do I Lock my Mac Without Logging Off

Q:

In Windows, I can use the “Ctrl + L” keyboard shortcut to quickly lock my screen without actually closing down any of my programs. How can I Lock my Mac without quitting everything and logging off?

A:

On the Mac, there really is no simple built-in way to quickly lock your display to prevent prying eyes from seeing what you are working on when you are refilling your coffee. Apple has enabled a quick lock function if you enable the “Show Status in Menu Bar” option in the Keychain Access Preferences. That will add a small lock icon in your menu bar which has an option to Lock Screen. This felt cumbersome to me and I was looking for an alternative that could be linked to a quick keyboard shortcut. I found a few applications that had functionality similar like this but I didn’t want to install a whole collection of things when I just want that one function?

I found a snippet of AppleScript that can handle the basic functionality that I was looking for and then I wrote a few additional lines of code to validate the command and make sure it verified that the user actually wanted to Lock the screen. This combined with QuicKeys by Startly gives me a solution that is perfect for my needs.

You can download the “Lock Screen” AppleScript application package HERE and just drag it into your “Applications” or “Utilities” folder.

For those that want it, here is the AppleScript that drives this little tool:

set normalCommand to "/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend"

set really to "Do you really want to lock the screen?"

set yesreally to button returned of (display dialog really buttons {"OK", "Cancel"} default button "OK")

if yesreally is "OK" then
do shell script normalCommand

end if