Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I want to change these behaviors from terminal:

  • Auto-login
  • Showing password after screensaver and sleep mode
  • Go to sleep mode after x minutes
  • Enable screensaver after x minutes
share|improve this question

3 Answers 3

up vote 5 down vote accepted

1) Auto-login

That one is tricky. The default is saved in

defaults read /Library/Preferences/com.apple.loginwindow autoLoginUser

But in order to turn it on or off, you need to do it as root.

Set it:

sudo defaults write /Library/Preferences/com.apple.loginwindow autoLoginUser ShortName

Delete it (turn it off):

sudo defaults delete /Library/Preferences/com.apple.loginwindow autoLoginUser

2) Showing password after screensaver and sleep mode

I've been trying to get that one to work, and I can't

You will see a lot of hints telling you that the answer is

defaults write com.apple.screensaver askForPassword 1

or variations like

defaults -currentHost write com.apple.screensaver askForPassword -int 1

and that should work, because if you turn it off via System Preferences, you will see:

% defaults read com.apple.screensaver
{
    askForPassword = 0;
    askForPasswordDelay = 0;
    tokenRemovalAction = 0;
}

and then if you turn it back on via System Preferences, you will see

% defaults read com.apple.screensaver
{
    askForPassword = 1;
    askForPasswordDelay = 0;
    tokenRemovalAction = 0;
}

BUT if turn it OFF and the quit System Preferences and change the setting using 'defaults write', when I re-launch System Preferences, it does not reflect that change.

I'd really like to know the answer to that one (preferably without osascript, but if there is no other way, I'll accept it).

3) Go to sleep mode after x minutes

Assuming you mean "have the computer go to sleep after x minutes" you want:

sudo pmset sleep 20

You can also use different settings specifically for when you are on battery (for MacBooks):

sudo pmset -b sleep 10

If you want to specify never sleeping when plugged in, use

sudo pmset -c sleep 0

4) Enable screensaver after x minutes

@Daniel's recommendation worked for me:

sudo osascript -e 'tell application "System Events" to set delay interval of screen saver preferences to 30'

You can use 'sudo pmset displaysleep X' to have the display sleep instead of using the screensaver.

share|improve this answer
    
It's strange, in fact, that defaults write … doesn't effect the System Preferences app in that case. –  mcb Oct 10 '11 at 18:43
    
hintsforums.macworld.com/archive/index.php/t-14085.html hmm… the same issue but still no solution. –  mcb Oct 10 '11 at 19:40
    
You should note that delay interval of screen saver preferences is in seconds even though the GUI is in minutes. So, setting it to 30 may give you unexpected results. –  Richard Bronosky Feb 13 '13 at 21:41
    
Also, version of OSX that have a slider will reflect the changes in System Preferences. Mountain Lion has a dropdown and does NOT reflect the changes. However, they work. –  Richard Bronosky Feb 13 '13 at 21:48

The osascript command and the System Events application are your friends here. Basically, you will be calling AppleScripts from the command line.

For instance,

  sudo osascript -e 'tell application "System Events" to set delay interval of screen saver preferences to 30'
  sudo osascript -e 'tell application "System Events" to set automatic login of security preferences to false'
  sudo osascript -e 'tell application "System Events" to set require password to wake of security preferences to true'

The first sets the screensaver to 30 seconds after the last action; the second disables autologin. The third requires a password for exiting the screensaver or waking from sleep (the settings for the two are linked). Exploring the System Events dictionary will help you put together the specifics you are looking for.

share|improve this answer
    
The first one worked to set the Screen Saver delay, but the other two did not work. –  TJ Luoma Oct 9 '11 at 8:18
    
They all worked on my machine. I suspect control panel locking might be the culprit. I'll research this further. –  Daniel Lawson Oct 9 '11 at 11:50

Screensaver Settings

/Library/Preferences/com.apple.screensaver.plist contains the system-wide settings which apply when a user account does not already have a setting for a given feature in ~/Library/Preferences/ByHost/com.apple.screensaver.MACADDRESS.plist.

To write to the system-wide file in /Library use

defaults write Library/Preferences/com.apple.screensaver

To write to the current user's file use

defaults write com.apple.screensaver

The value for a given setting in the user's file has priority over the value for the same setting in the system-wide file.

share|improve this answer
    
The preference for asking for a password after waking up is stored in ~/Library/Preferences/com.apple.screensaver.plist though at least on 10.7. It's also the file read by defaults read com.apple.screensaver; adding -currentHost would read the one in the ByHost directory. –  ؘؘؘ Jul 11 '12 at 8:37
    
And the string at the end was a MAC address in 10.4 and earlier, but it's now the hardware UUID shown by system_profiler | grep 'Hardware UUID'. –  ؘؘؘ Jul 11 '12 at 8:40

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.