MacOS – Automating Logging Into OS X After System Restart

apple-remote-desktopapplescriptautomationbashmacos

Background

I have a bunch of OS X Yosemite Mac Minis that are used as slaves by a Jenkins master machine to run Selenium tests using Google Chrome.

These slave machines get restarted on a daily basis.

Problem

After the restart, the machines are at a login screen asking for a username and password. Running Google Chrome remotely on the machines fails until a manual login is performed.

Is there a way to automate this login?

Things I have tried

  1. Executing a login script remotely on the Mac Mini using ssh root@<macmini-address> "bash -s" < ./login.sh where login.sh contains the following:
#!/bin/bash
osascript <<EOF
tell application "System Events"
keystroke "<replace with user>"
keystroke tab
delay 0.5
keystroke "<replace with password>"
delay 0.5
keystroke return
keystroke return
end tell
EOF

This results in the following error:

33:49: execution error: An error of type -10810 has occurred. (-10810)
  1. Sending the above AppleScript to the Mac Mini through Apple Remote Desktop (ARD).

This works but on some occasions, ARD is not able to send the script over to some Mac Minis showing a 'Client Software Not Active' message in the ARD status column.

Best Answer

macOS has an automated login feature.

  1. Choose System Preferences from the Apple menu (), then click Users & Groups.
  2. Click the lock , then enter account password.
  3. If you aren't logged in as an administrator, you're asked to enter an administrator's name and password.
  4. Click Login Options.
  5. Choose an account from from the “Automatic login” pop-up menu, then enter the password of that account.
  6. The account is now set up to log in automatically when your Mac starts up. You might still be asked to log in manually after logging out, switching back from another user account, or locking your screen.

enter image description here

Not all accounts work for automatic login. If you can't select your account, make sure FireVault is turned off and the account doesn't use an iCloud password for the login.