Apple - Disable screensaver password requirement from command line
If you are not forced to use defaults write you can use the following command. It interacts with the OS the same as if you were to utilize System Preferences.
TESTED ON:
- 10.5.x
- 10.6.x
- 10.7.x
- 10.8.x
- 10.9.x
sudo osascript -e 'tell application "System Events" to set require password to wake of security preferences to false'
NOTE: If the command is being run inside of a script that has been given root privileges you would not need the sudo.
osascript -e 'tell application "System Events" to set require password to wake of security preferences to false'
I ran into a similar issue, and found a solution from user Guillaume on this forum post. Basically, you need to force the screensaver to reread the password requirement preference, which you can do with a C program:
#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;
}
And compile this with:
cc -o /tmp/anywhereyouwantit/notif notif.c -framework CoreFoundation
Then call this program immediately after your call to defaults write