objective-ccocoasystem-preferences

Programmatically changing screen lock timeout


In my Cocoa application I would like to access and change the computer's screen lock timeout setting. Changing it in System Preferences does not require the user to enter the admin password.

System Preferences screenshot - Screen lock timeout

Unfortunately I couldn't find any information in the documentation, and I'm not sure what topic I should look into (security settings / prefPane programming).
Any help would be appreciated.


Solution

  • NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:@"/Users/new/Library/Preferences/com.apple.screensaver.plist"];
    [plistDict setObject:@"1" forKey:@"askForPassword"];
    [plistDict setObject:@"3600" forKey:@"askForPasswordDelay"];
    [plistDict writeToFile:@"/Users/new/Library/Preferences/com.apple.screensaver.plist" atomically:YES];  
    

    or From terminal

    defaults write com.apple.screensaver askForPasswordDelay 5