
Feb 16, '10 07:30:02AM • Contributed by: applebit
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
- Initially the script will help "wake up" computers before attempting to go further by simulating a few Down Arrow keystrokes.
- Any computers that are not on the username and password login window screen will be "encouraged" by clicking the Down Arrow multiple times and selecting that option. (It does not hurt anything to run this if the screen is already at the username/password fields.)
- The script will fill in each field, and does not depend on the correct field being highlighted -- unlike other scripts we have seen and used in the past.