After trying to script the login window multiple ways, I have come up with the perfect solution; this works 100% of the time when tested under OS X 10.4 and higher. We use this to log in computer(s) through Apple Remote Desktop by sending this script to computers sitting at the login window. This is great in a computer lab situation, where you may need to log in all the computers at once.
This method requires the username and password fields, but as long as you have a list of users with "Other..." displayed in the login window, it will work fine. Here's the script:
#!bin/sh cat >/tmp/Login_Automatically.sh <<-"EOF" if [[ "$(who | grep console)" == "" ]]; then # Runs ONLY if no one is logged in osascript <<EOT set username_ to "username" set password_ to "password" tell application "System Events" key code 125 -- Down Arrow key code 125 -- Down Arrow delay 1 key code 125 -- Down Arrow key code 125 -- Down Arrow key code 125 -- Down Arrow key code 125 -- Down Arrow key code 125 -- Down Arrow key code 125 -- Down Arrow delay 0.5 key code 36 -- Return delay 1 tell process "SecurityAgent" to set value of text field 1 of group 1 of window 1 to username_ tell process "SecurityAgent" to set value of text field 2 of group 1 of window 1 to password_ click button "Log In" of window 1 of application process "SecurityAgent" end tell EOT fi EOF chmod 755 /tmp/Login_Automatically.sh ./tmp/Login_Automatically.sh rm -f /tmp/Login_Automatically.sh
Mac OS X Hints
http://hints.macworld.com/article.php?story=2010021119293586