Wow. Didn’t take long for Snow Leopard to render my previous hint on how to lock your Mac’s screen utterly obsolete.
This is one of the things I love most about Mac OS X: Apple just keeps adding features that often eliminate the need for third party solutions to simple problems. In this particular case, we’re going to use a combination of Automator, a terminal command, Snow Leopard’s new improved Services and a system-wide keyboard shortcut to enable a hotkey that will suspend the currently logged in user session and display the Login Window as though you had chosen the “Login Window…” option from the Fast User Switching menu extra.
I know, enough with the chatter, get on with the tutorial! Just follow these steps and you’ll be locking your Mac running Mac OS X 10.6 Snow Leopard like it’s running Windows XP! Wait, did I just write that? Shudder. Sorry, I think I just threw up a little bit in my mouth. Here’s the tutorial:
- Open Automator (in your Applications folder) and choose Service from the list of templates provided and click the Choose button.
- In the left hand column under Library, select Utilities.
- In the second column, drag “Run Shell Script” to the right hand pane.
- At the top of the right hand pane where you dragged the Run Shell Script action, click on the menu next to “Service receives” and choose “no input”.
- Copy and paste the following Terminal command into the empty text area of the Run Shell Script action:
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspendThe entire command should be entered on a single line and note there is a space after “/Menu\”.
- Choose File–>Save, and give the new service a meaningful name like “Lock Computer” that will appear in the Services menu. Once you’ve done that, you can go to the Services menu (located in the current application menu, next to the Apple menu) and your newly created service should appear there.
- Next open System Preferences –> Keyboard –> Keyboard Shortcuts and select Services in the left column.
- Scroll down to the bottom and under the General category, you should see your newly created service listed there. Select it, then Double-click close to the right side of the selected line to reveal a field where you can enter a custom keyboard shortcut. Enter an easy to remember but unique keyboard shortcut (I decided to go with ctrl+option+command+L), and then quit System Preferences.
That’s it! Go ahead and test your keyboard shortcut!
Welcome back! As you should have just seen, pressing the assigned keyboard shortcut fast user switches to the login screen leaving all your programs running in the background waiting for you to log back in again. If you’re more mouse inclined, you can of course also lock your screen by choosing your Automator action from the Services menu. All accomplished with the awesome customization tools included with Mac OS X 10.6 Snow Leopard!



Awesome! Used your method exactly… worked like a charm.
thank you! this is just what i was trying to do!!!!!
Nice work around!
Too bad this work around was needed though.
Most modern OS’s seem to have screen lock features built in.
Muchas gracias por la info!
nice thanks! loving the cube animation.
Love the animation and the shortcut, but the shortcut doesn’t work globally. I need to have Automator running and in focus for the shortcut to work.
Is that expected, or am I doing something wrong?
Hi Aditya,
You’re definitely doing something wrong. Automator DOES NOT have to be running for this to work. I’d suggest looking over the instructions again carefully and maybe starting from scratch. Make sure you’re choosing Service in step 1.
You can delete your old service by looking for it in ~/Library/Services (that’s the Library folder in your Home folder). If you don’t see a file with the name of your service in there, then you didn’t select Service in step 1 when you created it.
Awesome tip. Quick question though…
Any way that this can be a “global” (for all user accounts) setting?
I had to go into each user account (4 of them) and create the new service and keyboard shortcut.
I tried putting the created service in /Users/Shared/Library/Services directory (the Services folder had to be created).
It’s no big deal if it can’t be done for all users, just would make it a lot easier if I were make a change in the future.
Thanks in advance if you come up with something.
Doug,
If you create the folder /Library/Services (that’s the global Library folder in the top level of your hard drive) and move the files into there from ~/Library/Services (that’s the Library folder in your user home folder), they will show up for all users of the computer. Only catch is the keyboard shortcuts still have to be set on a user by user basis, but this at least cuts out at least half your work.
well done
I have a Mac OS X Leopard (10.5.8), and I do not see the option ‘Service’ when I open up the Automator application. Please guide me on how I can create a service through automator. Thanks.
Hi Aniket, as the title and body of the article indicates, this hint is for Mac OS X 10.6 Snow Leopard only and will not work on Mac OS X 10.5 Leopard. Please see this previous hint for a solution that works in Leopard. It uses a small application as opposed to a service. Unfortunately Mac OS X Leopard doesn’t have the built-in ability to create custom services from Automator.
Thanks Madgunde! It’s awesome
I also used the keychain access trick, and it works fine too. Is there any disadvantage using that versus your script?
Not really, just personal preference.
What does it mean if my new service doesn’t display in the service listing?
You did something wrong, most likely you chose the wrong option in step 1.
That works beautifully! The problem with the is that the screensaver starts but all of the running applications suspend instead of running in the background. The same is true with the Keychain option.
I like this much more better.
[...] http://artofgeek.com/2009/09/08/lock-your-macs-screen-like-in-windows-snow-leopard-edition/? [...]
Thank you heaps
This is awesome. Thanks.
Thank You! I was able to recreate the service so that it works as a hotkey on all apps. I must have done something wrong the first time.
But, I noticed one thing… Whenever I lock the computer, it turns airport off, and the computer loses internet connection. Is there a way not to do that?
Aditya
See this previous comment thread for your answer.
In future, please use the “Reply” link when replying to comments. This way the conversation stays together and remains in context.
Kewl! The most important thing for me is that you have removed my fear of AppleScript and Automator. I have beginner level CLI skills, and have always been scared to death of moving forward and deeper into the power of Unix and scripting…thank you! So much to learn. What an adventure!
Thanks much. This is very helpful!
Anyone else notice that the screen lock has some race conditions? Tomorrow I’ll post on YouTube a video where the screen saver’s lock ‘activated’, but I could still interact with the system (open up applications, terminal windows, etc, and do as I pleased) without ever entering username/password even though it was asking for it. Click on my website to see the video, or click here….
Wow. Thanks for posting that. Do you know what versions of Mac OS X are affected? Just curious if that was a vulnerability that was patched already.
In any case, it’s a good reason to use my hint in this article to activate the fast user switching login screen instead of the screensaver as some commenters seem to prefer. Personally, I never liked the idea of using the screensaver for this very reason.
It affects all current versions of OSX, to include Leopard and Snow Leopard (server and workstation versions). No, it has no been patched yet.
I followed everything you said Up. I even created a Services folder in the Root directory so that all users can have access to this feature. It is displayed in the services list and when I click from there the Login Window appears. But when I type the shortcut I have set Command + L it just makes a sound and does not Lock my Mac. I even changed the shortcut to Command Option L and still does not. I have Mac OSX 10.6.4. Is there something I’m missing here?
Remember that keyboard shortcuts are user profile specific so you’ll likely have to create them manually for each user. Did you try the keyboard shortcut I suggested in the hint? Ctrl+Opt+Cmd+L? I find most shortcuts using just Cmd or Option (or both) don’t work, probably because they’re reserved by the OS.
Thanks for the ifo, its amazing how we don’t even use 50% of the apps that comes with Mac OX. I def have to take UNIX and Linux
Another great article – I love this website