2

I’m running MacBook with macOS Sierra version 10.12.5. I would like to know the commandline setting to change to UNCHECK the “Disable Automatic login” under “Security & Privacy”. I can do this by using the UI. However since I have to redo this repeatedly, I’m trying to do this using a script.


Edit: This is a corporate owned MacBook. If I want to do this, I have to do it everytime I reboot because this setting gets reset on reboot. This may also be the reason why my attempt mentioned below did not work. However, I can do this manually, so the settings are not so restrictive, so I'm guessing I might be able to do this on the commandline.


enter image description here

I tried the process mentioned in Editing System Preferences via Terminal - but the only difference I get is in com.apple.loginwindow.plist where it differs in the LoginwindowText. I don’t think this is the setting.

Can someone tell me which is the commandline setting for unchecking this box?


Edit: In response to Mark's suggestion, I tried the following:

try
    set thePW to "mypassword"


    tell application "System Events"
        tell application "System Preferences"
            activate
        end tell
        tell process "System Preferences"
            activate
            delay 1
            click menu item "Security & Privacy" of menu "View" of menu bar 1
            delay 3
            if title of button 1 of window 1 is "Click the lock to make changes." then
                click button 1 of window 1
                delay 2
                keystroke thePW
                keystroke return
            end if
            get properties
            --set properties to {automatic login:true}
        end tell
    end tell
on error errMsg
    display dialog errMsg
end try

This code starts “Security & Privacy” and puts in my password to login. Unfortunately, the get properties does not show me anything about automatic login. I get the following result:

{has scripting terminology:true, bundle identifier:"com.apple.systempreferences", file:alias "Macintosh HD:Applications:System Preferences.app:" of application "System Events", creator type:"sprf", subrole:missing value, entire contents:{}, selected:missing value, application file:alias "Macintosh HD:Applications:System Preferences.app:" of application "System Events", orientation:missing value, role:"AXApplication", accepts high level events:true, file type:"APPL", value:missing value, position:missing value, id:28015286, displayed name:"System Preferences", name:"System Preferences", class:application process, background only:false, frontmost:true, size:missing value, visible:true, Classic:false, partition space used:0, role description:"application", maximum value:missing value, architecture:"x86_64", short name:"System Preferences", focused:missing value, minimum value:missing value, help:missing value, title:"System Preferences", accepts remote events:false, total partition size:0, description:"application", accessibility description:missing value, enabled:missing value, unix id:57066}

In the above mentioned code I have commented out the set properties to {automatic login:true} line. If I enable it I get the error:

error "System Events got an error: Can't make {automatic login: true} into type of properties of process." number -1700 from {automatic login: true}

I'd be grateful for any help.


  • "I have to redo this repeatedly"... why? – Tetsujin Nov 30 '17 at 21:15
  • 1
    Thank you Tetsujin. I added information to my post why I have to do this repeatedly. – O.O. Dec 1 '17 at 15:19
  • You said, "This code starts “Security & Privacy” and puts in my password to login. Unfortunately, the get properties does not show me anything about automatic login.", and there is no reason why you should get properties of automatic login because you are not asking security preferences for its properties, you're asking "System Preferences" for its properties! Try using.: tell application "System Events" to get properties of security preferences BTW You do not need that in the code to set the properties, only to check what the properties are. – user3439894 Dec 1 '17 at 21:31
1

I do not recommend doing this, as it increases security risk, but to answer the question, see below.

I do not have the same macOS version so was not able to test, but you can try creating an AppleScript to do this for you.

Create AppleScript to Disable automatic logic and save to ~/bin/disable-automatic-login.osa

#!/usr/bin/osascript
-- AppleScript to set Security settings "Disable automatic login" unchecked

tell application "System Events"
    tell security preferences
        set properties to { automatic login: true }
    end tell
end tell

Make sure to enable execution chmod +x ~/bin/disable-automatic-login.osa

Add ~/bin to path and run $ disable-automatic-login.osa to disable the automatic login.

Troubleshooting

The documentation is out of date, so the properties may be incorrect, but the idea is the same. You can discover the properties in the Script Editor.app by running the following in the app:

tell application "System Events"
    tell security preferences
        get properties
    end tell
end tell

and change the script with the correct properties.

Extra: Automatic Launch at login with launchd

See http://developernotes.com/archive/2011/04/06/169.aspx

  • Thank you @Mark. I'm curious which version of macOs are you running. When I run both of the above mentioned scripts I get: error "System Events got an error: AppleEvent handler failed." number -10000 But at least you have put me on the correct path – O.O. Dec 1 '17 at 19:58
  • Changed script and tested on my system. It works, albeit asks for administrative permission. But that may be because of the way I've setup my local machine. – Mark Dec 1 '17 at 22:46
  • Thank you Mark. This still doesn't work on my system. I do get the dialog for the administrative permission, and after putting in my password it does nothing. May be it's a different version of the OS. I'm marking this answer as correct, because its the closest I could get. – O.O. Dec 4 '17 at 15:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .