Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Script the Login window through Apple Remote Desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Script the Login window through Apple Remote Desktop
Authored by: applebit on Mar 09, '12 08:35:52AM
Ok, here is updated code that has now been tested and works 10.5, 10.6, and 10.7. Enjoy! I suppose I could be ambitious and try it on the upcoming 10.8 but meh, it's not mainstream enough for me to put effort into it yet.


#!bin/sh
cat >/tmp/Login_Automatically.sh <<-"EOF"
loginwindow_username='username'
loginwindow_password='password'

if [[ "$(/usr/bin/who | /usr/bin/grep console)" == "" ]]; then # Run this
code ONLY if NO users are logged in
	osascript -e 'tell application "System Events"' -e 'repeat 2 times' -e
'repeat 10 times' -e 'key code 125 -- Down Arrow' -e 'end repeat' -e
'delay 1' -e 'end repeat' -e 'key code 36 -- Return' -e 'end tell'
	sleep 1
	OperatingSystem=$(sw_vers -productVersion | cut -c 1-4)
	if [[ "$OperatingSystem" != "10.7" ]]; then
		osascript -e 'tell application "System Events"' -e 'tell process
"SecurityAgent" to set value of text field 1 of group 1 of window 1 to
"'$loginwindow_username'"' -e 'tell process "SecurityAgent" to set value
of text field 2 of group 1 of window 1 to "'$loginwindow_password'"' -e
'click button "Log In" of window 1 of application process "SecurityAgent"'
-e 'end tell'
		rr=$?
	else
		osascript -e 'set username_ to "'$loginwindow_username'"' -e 'set
password_ to "'$loginwindow_password'"' -e 'tell application "System
Events"' -e 'tell process "SecurityAgent" to set value of text field 2 of
window 1 to username_' -e 'tell process "SecurityAgent" to set value of
text field 1 of window 1 to password_' -e 'key code 36' -e 'end tell'
		rr=$?
	fi
fi

EOF
chmod 755 /tmp/Login_Automatically.sh
./tmp/Login_Automatically.sh
rm -f /tmp/Login_Automatically.sh

---
Jon McCullough
Systems Support Specialist


[ Reply to This | # ]