Posted on 10-25-2012 03:40 PM
On a mailing list we have for some school districts in the area someone asked if there was a way to login a bunch of macs in a lab with different usernames and password simultaneously via ARD using something like the 'tell System Events to keystroke' method.
He sent it just a few minutes before I started my lunch break and it sounded intriguing. After a few false starts and a helpful tip via gist comment here it is.
I figured it could be useful if modified to check for even or odd numbered machines and use a test_student or test_teacher account to dee if different policies etc. are being applied.
https://gist.github.com/3954329
#!/bin/bash
computer_name=$(scutil --get ComputerName)
login() {
/usr/bin/osascript << EOF
tell application "System Events"
keystroke "${1}"
keystroke return
delay 1
keystroke "${2}"
keystroke return
end tell
EOF
}
case "${computer_name}" in
lab_imac-01) login user1 "pass1" ;;
lab_imac-02) login user2 "pass2" ;;
*) echo "ERROR: computername not found in case!"; exit 1 ;;
esac
Posted on 10-25-2012 04:09 PM
That script is pretty similar to one I came up with, but yours has more logic with the case statement and the login as a function. I noticed in Lion, using AppleScript to just enter stuff at the loginwindow wasn't really working that well. See this thread: https://jamfnation.jamfsoftware.com/discussion.html?id=5560
Here is the script I use in Lion, which could be modified with a case statement like your example.
#!/bin/sh
#Enable access for assistive devices in Lion
touch /private/var/db/.AccessibilityAPIEnabled
#enter username and password
osascript -e <<EOF 'tell application "System Events"
tell process "SecurityAgent"
set value of text field 1 of window "Login" to "testing_user"
set value of text field 2 of window "Login" to "password"
end tell
tell application "system events" to keystroke return
tell application "system events" to keystroke return
end tell'
EOF
Posted on 10-25-2012 04:35 PM
Nice. I'll look into it.
These machines I am testing against tonight are all 10.6.8 :( Will look into L & ML tomorrow.
I need to leave to go to a meeting but after doing the rest of my casual email reading etc. I came back around to what I thought would be useful, doing one set of credentials for even and one set for odd. This is still untested as I really need to jet but I wanted to toss it up.
#!/bin/bash
computer_name=$(scutil --get ComputerName)
computer_num=Even
# take the final character of the computer_name (our lab convention is station # at end)
# if that number modulus 2 is 1 then set computer_num=Odd
[[ $((${computer_name:str$((-1)):1} % 2)) == 1 ]] && computer_num=Odd
login() {
/usr/bin/osascript << EOF
tell application "System Events"
keystroke "${1}"
keystroke return
delay 1
keystroke "${2}"
keystroke return
end tell
EOF
}
# just add more case statements as needed with the
# computername as the choice and the username and password
case "${computer_num}" in
Even)
login user1 "pass1"
;;
Odd)
login user2 "pass2"
;;
*)
echo "ERROR: How did this even happen?"
exit 1
;;
esac
Posted on 10-26-2012 04:49 AM
I meant to ask--how do you need to determine what computers use which login credentials? Is it as simple as you said, using every odd or even computer?
Posted on 10-27-2012 07:11 PM
Okay ...I'll ask . What would something like this be used for? is it the delayed login Snow Leopard thing ?
Posted on 10-28-2012 09:23 AM
LSinNy, what do you mean delayed login?
I use this in the High School to log all the computers in to a local "testing" account and then launch the testing software so students can just come in, sit down, and take the test instead of logging in and launching the software themselves. We currently are not using OD or AD with the Macs, so this is a faster way to get them up and running for the class.
I have also used it in instances where I wanted to open the software on a whole lab to see if some changes I made were applied correctly to the whole lab. This let me avoid touching each computer and quickly see that all the computers were operating the same.
Posted on 10-30-2012 09:48 AM
LSinNY, the original request came from someone who was looking to track down performance issues when a class of students came in so he wanted to be able to login 30 different accounts to 30 different iMacs simultaneously.
For me personally it is as I stated above testing different policies coming down for teachers vs. students on an entire lab of machines. Opening applications as students to ensure there are no preferences or pop-up windows I forgot to deal with etc. etc.
Posted on 10-30-2012 09:50 AM
Jacob to your question yea I would just pick iMac-01,03,05 is going to be mytestuser_stu and iMac-02,04,06 is going to be mytestuser_fac etc.
EDITED: for *hopefully* more clarity.
How the second even/odd script would work is based on our naming convention. For student labs it is like so.
S556-MD-01
S = building
556 = room
M = Mac OS (many are dual boot)
D = Desktop
01 = station number
So the script above gets the last character of the name and determines if it is an even or odd number, sets the variable and then the case statement would execute the function with the different username/password combos.
See the above post for the reason for doing the first version.