Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 com.apple.screensaver askForPassword -int 0
defaults -currentHost write com.apple.screensaver askForPassword -int 1

which seems to update /Users/USER/Library/Preferences/com.apple.screensaver.plist successfully.

However when manually updating or using the terminal to update

askForPassword

, 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

2 Answers 2

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("com.apple.loginwindow.notify"));
  CFMessagePortSendRequest(port, 500, 0, 0, 0, 0, 0);
  CFRelease(port);
  return 0;
}

(source: http://hintsforums.macworld.com/archive/index.php/t-49718.html )

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 com.apple.screensaver
{
    askForPassword = 1;
    askForPasswordDelay = 60;
}

So I would try changing the delay as well:

$ defaults write com.apple.screensaver 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

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.