Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to speed up my enabling and disabling of the security/password feature on OS X. Specifically in this case Mountain Lion 10.8.4.

I currently have a hot corner (Plus the shortcut ctrl + shift + EJECT) set to start my screensaver on my Mac. This in turn requires a password immediately after the screensaver has kicked-in. I use this feature when working in an environment where I wish to secure my active Mac in a shared situation.

I am trying to enable, from the terminal, a quick way to enable or disable the "Require password X after sleep or screen saver begins".

I have tried

defaults -currentHost write askForPassword -int 0
defaults -currentHost write askForPassword -int 1

which seems to update /Users/USER/Library/Preferences/ successfully.

However when manually updating or using the terminal to update


, it seems to be getting ignored, thus nothing is functionally changing.

I'd prefer to do it from the terminal if possible but am open to other suggestions if not. So far all commands are run as non-root.

Any Help or guidance on the matter is more than welcome

share|improve this question
up vote 0 down vote accepted

You can killall SystemUIServer or, if you want, you could compile this code and run it after you run the defaults command. It is less drastic than the killall command, although it requires the developer tools and C compiler to be installed.

#include <CoreFoundation/CoreFoundation.h>

int main(int argc, char ** argv) {
  CFMessagePortRef port = CFMessagePortCreateRemote(NULL, CFSTR(""));
  CFMessagePortSendRequest(port, 500, 0, 0, 0, 0, 0);
  return 0;

(source: )

share|improve this answer
I've been trying to get this to work but when I try compile the program i get an error Undefined symbols for architecture x86_64: "_CFMessagePortCreateRemote", referenced from: _main in main.o "_CFMessagePortSendRequest", referenced from: _main in main.o "_CFRelease", referenced from: _main in main.o "___CFConstantStringClassReference", referenced from: CFString in main.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) Any ideas? – Badger Jul 24 '13 at 17:47
When you run gcc, you need to link the Cocoa framework. gcc -framework Cocoa -o SendMessage SendMessage.m – Kent Jul 24 '13 at 22:03
And, I just realized you compiled with clang, not gcc. The error's root cause is the same; but, the syntax to include a framework with clang is slightly different. I don't have a clang compiler handy to test; but, there are plenty of examples around the web. – Kent Jul 24 '13 at 22:13
Cheers for all your help and patience. Worked like a charm. I lost my previous SU account so can't Vote Up the answer but hopefully the tick is enough. Thanks – Badger Jul 25 '13 at 21:08
Glad it worked. If you used clang command line, could you add the syntax in a comment? It might be useful if someone comes here looking for the same thing in the future. – Kent Jul 25 '13 at 23:12

Well, it didn't work to me as well. I'have listed the defaults and find following:

$ defaults read
    askForPassword = 1;
    askForPasswordDelay = 60;

So I would try changing the delay as well:

$ defaults write askForPasswordDelay -int 1

It might help you, but does not work on the OS X version coming up, even with killing the SystemUIServer...

share|improve this answer

You must log in to answer this question.

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