Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm trying to find out whether there is any kind of equivalent command line one-liner which replicates the exact identical functionality of the 'Lock Screen' menu option available via the Keychain app in OS X 10.6

I'm aware of the all the 'usual' solutions (sleep/screensaver preferences to require a password on reactivation) but these are not suitable to me.

I'm also aware of this option:

/System/Library/CoreServices/Menu\ Extras/user.menu/Contents/Resources/CGSession -suspend

which is also not suitable for me.

The perfect functionality is the 'Lock Screen' option however I have not yet found an elegant way to call it.

At the moment, I am calling via Automator, which isn't elegant!

I have read much about this issue and my understanding is that no-one has yet found the 'holy grail' but I was wondering whether that might have changed.

Thanks.

share|improve this question
What do you call with Automator ? – Matthieu Riegler Jan 26 at 13:37
Sorry, I should have been more clear... I have recorded a 'Watch Me Do' in Automator (tied to a system keyboard shortcut) which, literally, moves the mouse to the menu option and selects it. It works, but it's slow and not at all elegant! – user40433 Jan 26 at 13:47
2  
What is wrong with setting the Security preferences to require a password when the screen saver is active and then using a hot corner to activate the screen saver? That is fast and elegant, but you said you didn't like that solution. – Mark Thalman Jan 26 at 13:57
2  
It's a pragmatic suggestion and one I've tried on and off over many years of usage but the nature of my work patterns means that this gets in the way >80% of the time. I need the ability to respond (physically) to engineering requests and emergencies and immediately lock the screen but equally have remote access to the box whilst it also maintains all of its existing connections and background tasks. – user40433 Jan 26 at 15:57
Your question would likely be much easier to answer if it gave more specific details. Where is the Lock Screen menu item in the Keychain app? What exactly does it do? Why are the current solutions unsuitable? We all understand "elegant," but it seems like your requirements are more specific than that. Editing your question should help. – Tyler Wayne Jan 30 at 6:18
show 3 more comments

9 Answers

Set the preferences to lock the screen when the screen saver is active.

Security & Privacy Preference Pane

Then you can use this terminal command to start the screen saver.

/System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine

As far as I can tell this is exactly what the Keychain menu item does.

share|improve this answer
Thanks you for your comment but this is what I've battled with for too long and am trying to find an alternative to. – user40433 Jan 26 at 16:01
Just for clarity and completeness, I should that the above does indeed start the screensaver but it does not do what the 'Lock Screen' menu function offers. – user40433 Jan 26 at 16:06
1  
Then you need to be more specific as to what exactly you are looking for. – Mark Thalman Jan 26 at 16:17
Hmmm... not sure I can be any more specific or succinct then the opening paragraph in my original question! – user40433 Jan 26 at 16:23
1  
I had a chance to test on 10.6.8. On that OS the monitor is turned of and the session is locked. I found a programatic way to do this, but it is not built in. – Mark Thalman Jan 29 at 14:05
show 4 more comments

I use Alfred →

enter image description here

The universal hotkey allows me to activate it using a keyboard.

share|improve this answer

I think the answer to your question is "No, there isn't a command line way to do this."

Because this is a menu bar item, it's not something that you can access easily using Keyboard Maestro or another similar tool.

However, if you are not averse to a solution using a 3rd party app, QuickLock will let you do this.

It's a free (donations accepted) app which will let you assign a keyboard shortcut to lock the screen. There's also a menu bar item which you can click to lock the screen.

The app will let you set a password (separate from your account password).

It does not require the use of password with screensaver, it's all completely separate.

You can see a video of it in action at http://www.youtube.com/watch?v=SBHwykPB19o

p.s. when the screen is locked, type your password to unlock it. I was confused because I expected to see a password field. There is none. You just type the password.

p.p.s. I've only used this for a few minutes, so there may be some other issues with it I'm not aware of, but it seems to fit the bill.

share|improve this answer
Thanks for your contribution... although not what I set out looking for (I love open source and DIY methods!) it does look very interesting and appears to offer the functionality that I need, albeit in a 3rd party app. I'll look into it more closely. Thanks! – user40433 Jan 29 at 22:30
I'd love to find a way to do it too, but I don't think there is one. – TJ Luoma Jan 30 at 15:07

The Mac is not designed to provide you with such an option. However, this article explains a workaround using QuickSilver. While I can't understand why you don't like the solution Apple provides natively, I do wish you luck on finding a solution.

share|improve this answer

Set the preferences to lock the screen when the screen saver is active.

Security & Privacy Preference Pane

Then set a "Hot Corner" to start the screen saver:

Screen Saver Preference Pane

Now just move the mouse to the upper Right corner to activate the screen saver and lock the screen.

share|improve this answer
Thank you Mark. I'm very familiar with all this functionality but it's not the solution I am seeking. The Lock Screen functionality is perfect for me but the means of invocation is cluncky and it is the latter that I am trying to address. – user40433 Jan 26 at 16:03

I use the Screensaver password setting with a keystroke (Ctrl+Shift+Eject) on 10.6.8, and from what I can see, it does the same as the Lock Screen item from the Keychain Access task bar icon.

I know that this is similar to some of the other answers, but instead of the "hot corner", it uses a keystroke, which is more convenient for me.

This solution is described in more detail here, that's where I got it from: http://osxdaily.com/2011/01/17/lock-screen-mac/

Have been using this for several years now without problems.

share|improve this answer
Thanks but, unfortunately this requires that the option to "require screensaver when returning from sleep or screensaver" option sis checked and, as mentioned earlier, this is not something I wish to have engaged. – user40433 Jan 30 at 13:32

I use BetterTouchTool for that purpose and assigned a keyboard shortcut to "Switch to login screen" (which is lock screen): doesn't fulfill the command line requirement but may be helpful to you anyway.

keyboard shortcut in BetterTouchTool to lock screen

share|improve this answer
Thanks for your help and suggestion. Along with QuickLock mentioned above by @TJLuoma BetterTouchTool (although not the method I set out to find) does appear to come very close to my functional objectives. I will look more closely at this... thanks. – user40433 Jan 31 at 20:48

Well, just combine two of the above answers. Run this command:

open -a /System/Library/Frameworks/ScreenSaver.framework//Versions/A/Resources/ScreenSaverEngine.app

After having set the Security & Privacy preferences to ask for a password immediately. Make an alias for your shell if you want to make the command easier to execute.

share|improve this answer
Yes but, as mentioned above, I don't wish to have the Security & Privacy preferences to always require a password immediately. This is why the Lock Screen command functionality (specifically) is so cool - it provides the level of security I require on a completely ad hoc basis. – user40433 Feb 1 at 22:12

I'm not quite sure I understand your issue here. If you require a password on screensaver, it will not stop processes from running or block you from remotely accessing your Mac. I have this option set (using ControlPlane to activate it at work and deactivate it at home) and I have never once had the system refuse to respond to a Remote Desktop, VNC, or SSH connection. In all cases where GUI access is required I just need to input the password; SSH uses key pair so no password is requested. If you don't want apps to sleep, then make sure the system power settings are such that it will not enter system sleep before you return. Just set the sleep timeout to a long delay. If you just don't want to be bothered to enter a password when you are sitting in front of the computer and working, then increase the screensaver delay to a longer time before it activates, or add a 1 min delay between screensaver and password prompt so that you have a chance to catch it before it locks you out.

I use ctrl-shift-eject to lock the screen. It's fast, simple, and it works. This is the built-in way to lock the screen. No one is likely to come up with an alternative simply because replicating the functions already baked in to the OS is a little too redundant for anyone to put a lot of time into pursuing.

As far as I can tell there is no "lock screen" option in Keychain in 10.8 anyway, so your preferred solution is not going to exist if you ever upgrade. Edit: Didn't notice this in Keychain preferences; yes, it is still there in 10.8.

If you are using Automator for this can't you just package the script as an app and assign a hotkey combo or leave it in the Dock for quick access?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.