Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 6 down vote accepted

1) Auto-login

That one is tricky. The default is saved in

defaults read /Library/Preferences/ autoLoginUser

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

Set it:

sudo defaults write /Library/Preferences/ autoLoginUser ShortName

Delete it (turn it off):

sudo defaults delete /Library/Preferences/ 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 askForPassword 1

or variations like

defaults -currentHost write askForPassword -int 1

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

% defaults read
    askForPassword = 0;
    askForPasswordDelay = 0;
    tokenRemovalAction = 0;

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

% defaults read
    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. – Lenar Hoyt Oct 10 '11 at 18:43 hmm… the same issue but still no solution. – Lenar Hoyt 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. – Bruno 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. – Bruno 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 Oct 9 '11 at 11:50

Screensaver Settings

/Library/Preferences/ 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/

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

defaults write Library/Preferences/

To write to the current user's file use

defaults write

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/ though at least on 10.7. It's also the file read by defaults read; adding -currentHost would read the one in the ByHost directory. – user495470 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'. – user495470 Jul 11 '12 at 8:40

Your Answer


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.