Skip to main content
Solved

Set Screen Saver to Turn on After x minutes (defaults command not working)

  • August 5, 2014
  • 7 replies
  • 64 views

Forum|alt.badge.img+11

Hi there,

I'm trying the following command to set the screen saver to turn on after 15 minutes:

sudo defaults -currentHost write com.apple.screensaver idleTime -900

Which yielded the proper result:

:~ jkuo$ defaults -currentHost read com.apple.screensaver
{
    CleanExit = YES;
    PrefsVersion = 100;
    idleTime = 900;
    moduleDict =     {
        moduleName = Arabesque;
        path = "/System/Library/Screen Savers/Arabesque.qtz";
        type = 1;
    };
}

It worked right the first time, but then after I changed the setting in system preferences and tried to change it again, it seems like the defaults command doesn't do anything anymore.

:Scripts jkuo$ sudo defaults -currentHost write com.apple.screensaver idleTime -1000
:Scripts jkuo$ defaults -currentHost read com.apple.screensaver idleTime
120

Any ideas what might be happening here?

Thanks!

Best answer by nkalister

well, I've been so annoyed by the unreliability of the screensaver settings that I actually set it at the computer level using MCX as well as for the user with defaults:

# Computer MCX
sleep .5
dscl . -mcxset /Computers/localhost com.apple.screensaver idleTime always -int 1800
dscl . -mcxset /Computers/localhost com.apple.screensaver askForPassword always -int 1
dscl . -mcxset /Computers/localhost com.apple.screensaver askForPasswordDelay always -int 0         
# Computer Defaults Writes
sleep .5
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver askForPassword -int 1"
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver askForPasswordDelay -int 0"
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver idleTime 1800"

see if that makes everything look correct . . . also, I believe you need to at least quit and relaunch SysPrefs before it'll show the new value.

7 replies

Forum|alt.badge.img+10
  • Contributor
  • August 6, 2014

@jkuo][/url - Managed Preferences may be an alternate method. It's what I have used in the past.


Forum|alt.badge.img+19
  • Contributor
  • August 6, 2014

run the command as the user:

sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver idleTime 1800"

Forum|alt.badge.img+11
  • Author
  • Contributor
  • August 6, 2014

@nkalister][/url - bingo, that did the trick!

Now the next mystery - even though I set it to, say, 30 seconds, the screen saver still isn't turning on after that amount of time. Is there another place I'm missing where I need to change a setting?

Also, even though the defaults read shows 30, in the System Preferences Panel is still shows the last set amount:

jkuo$ defaults -currentHost read com.apple.screensaver idleTime
30

But in System Preferences-->Screen Saver, it says "10 minutes"

Any ideas on what I'm missing here?

Thanks!


Forum|alt.badge.img+19
  • Contributor
  • Answer
  • August 6, 2014

well, I've been so annoyed by the unreliability of the screensaver settings that I actually set it at the computer level using MCX as well as for the user with defaults:

# Computer MCX
sleep .5
dscl . -mcxset /Computers/localhost com.apple.screensaver idleTime always -int 1800
dscl . -mcxset /Computers/localhost com.apple.screensaver askForPassword always -int 1
dscl . -mcxset /Computers/localhost com.apple.screensaver askForPasswordDelay always -int 0         
# Computer Defaults Writes
sleep .5
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver askForPassword -int 1"
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver askForPasswordDelay -int 0"
sudo su -l "$LoggedInUser" -c "defaults -currentHost write com.apple.screensaver idleTime 1800"

see if that makes everything look correct . . . also, I believe you need to at least quit and relaunch SysPrefs before it'll show the new value.


golbiga
Forum|alt.badge.img+21
  • Employee
  • August 7, 2014

Have you thought about using a profile instead? Something along the lines of this should work for you, just adjust the idleTime to 900. https://github.com/golbiga/Profiles/blob/master/screensaver.mobileconfig

Allen


adhuston
Forum|alt.badge.img+9
  • Contributor
  • August 7, 2014

Sounds like preference caching to me. I had a similar problem with setting icons on the Dock and the Ask For Screen Saver Password when waking a computer from Screen Saver or Sleep. I found that killing the cfprefsd process sometimes fixes it. Other times it takes a reboot. Try adding killall cfprefsd at the end of the script after you run the defaults command.

http://hints.macworld.com/comment.php?mode=view&cid=132659


Forum|alt.badge.img+19
  • Contributor
  • August 7, 2014

defaults commands are cfprefsd safe, according to apple, but YMMV. in my experience with cfprefsd, defaults commands work fine but plistbuddy or replacing the entire plist file will trigger a replacement from cache by cfprefsd.