Script ard to log in selected computers with different accounts

I have a need to select multiple computers or a list of computers in apple remote desktop, and then log them all in using different accounts.

Right now i am able to use the send unix command feature of ard and the following script to garphically log in multiple computers using the same account.

osascript -e ‘tell application “System Events”’ -e ‘keystroke “LOGIN_NAME”’ -e ‘keystroke tab’ -e ‘delay 0.5’ -e ‘keystroke “PASSWORDHERE”’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’

Sometimes i need to log a group of computers in with unique accounts, like test1, test2, test3, etc. And this can be a little time consuming when i need to do it multiple times.

What i am hoping to do somehow is select a computer list or multiple computers in ard, and then send the above script to each one of them but the login name changes or the number at the end of the login name increments 1 each time it is sent. I am thinking that the login script cant be sent to all computers at the same time but that it will need to be sent to each computer in the list in one at a time.

Any ideas or help?

Mark

I have managed to get some code to do a portion of what i am trying to accomplish.

The following code will go through all the computers in my list and display the name to me, then remove it from the list and go on to the next computer.

tell application “System Events”
tell application “Remote Desktop”
activate
repeat
set currentcomputer to name of first computer in computer list “Untitled List”
display dialog currentcomputer
remove computer currentcomputer from computer list “Untitled List”
set currentcomputer to {}
end repeat
end tell
end tell

But what i want is the following send unix command to be sent to each computer:

osascript -e ‘tell application “System Events”’ -e ‘keystroke “LOGIN_NAME”’ -e ‘keystroke tab’ -e ‘delay 0.5’ -e ‘keystroke “PASSWORDHERE”’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’

But instead of all computers getting the same login name, they will each get a different login name, like test01, test02 test03…

I tried to replace the line display dialog currentcomputer, with some lines of gui scripting that would click on the send unix command button and fill in the appropriate fields but rather than send the command to each computer it seems to keep sending it to the same computer even if it is no longer in the list…

That script is as follows: For testing purposes i am using say test as the temporary unix command instead of the actual login script until i get it closer to working.

tell application “System Events”
tell application “Remote Desktop”
activate
repeat
set currentcomputer to name of first computer in computer list “Untitled List”
–display dialog currentcomputer
tell application “System Events”
click UI element “UNIX” of tool bar 1 of window “Remote Desktop” of application process “Remote Desktop”
click text area 1 of scroll area 1 of splitter group 1 of window “untitled” of application process “Remote Desktop”
keystroke “say test”
click radio button “User:” of radio group 1 of group 1 of splitter group 1 of window “Untitled” of application process “Remote Desktop”
click text field 1 of group 1 of splitter group 1 of window “untitled” of application process “Remote Desktop”
keystroke “root”
click UI element “Send” of window “Untitled” of application process “Remote Desktop”
end tell

		remove computer currentcomputer from computer list "Untitled List"
		set currentcomputer to {}
	end repeat
end tell

end tell

I know this is probably horrible code, but i am not a script writer, just someone trying to find a solution to a problem.

Think i almost have it.

set num to 1
tell application “Remote Desktop”
set theComputers to the selection
repeat with x in theComputers
set num to num + 1
set thetask to make new send unix command task with properties {name:“Multigui Login”, script:“osascript -e ‘tell application "System Events"’ -e ‘keystroke "lab1"’ -e ‘keystroke tab’ -e ‘delay 0.5’ -e ‘keystroke "PASSWORDHERE"’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’”, showing output:false, user:“root”}
execute thetask on x
end repeat
end tell

The only thing i am having trouble with now is how to get the incrementing variable num to replace the number 1 in lab1. I dont know what the syntax is.

Please help, i have figured this all out by myself so far.

First separate the script from the task, insert the variable num instead of 1. After executing the task increase num.
Try this:

set num to 1
tell application "Remote Desktop"
	set theComputers to the selection
	repeat with x in theComputers
		set theScript to "osascript -e 'tell application \"System Events\"' -e 'keystroke \"lab" & num & "\"' -e 'keystroke tab' -e 'delay 0.5' -e 'keystroke \"PASSWORDHERE\"' -e 'delay 0.5' -e 'keystroke return' -e 'end tell'"
		set thetask to make new send unix command task with properties {name:"Multigui Login", script:theScript, showing output:false, user:"root"}
		execute thetask on x
		set num to num + 1
	end repeat
end tell

Before seeing your reply I was able to come up with this one here, but i like the simplicity of yours.

set y to 1
tell application “Remote Desktop”
set theComputers to the selection
repeat with x in theComputers
set y to y + 1
set theCommand to “”
set theCommand to theCommand & “osascript -e ‘tell application "System Events"’ -e 'keystroke "lab”
set theCommand to theCommand & y
set theCommand to theCommand & “"’ -e ‘keystroke tab’ -e ‘delay 0.5’ -e ‘keystroke "PASSWORDHERE"’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’”
set thetask to make new send unix command task with properties {name:“Multigui Login”, script:theCommand, showing output:false, user:“root”}
execute thetask on x
end repeat
end tell

So this is what i have now and it is working.

set num to 1 as text
tell application “Remote Desktop”
set theComputers to the selection
repeat with x in theComputers
if length of num < 2 then
set num to “0” & num as text
end if
set thescript to “osascript -e ‘tell application "System Events"’ -e 'keystroke "lab” & num & “"’ -e ‘keystroke tab’ -e ‘delay 0.5’ -e ‘keystroke "passwordhere"’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’”
set thetask to make new send unix command task with properties {name:“Multigui Login”, script:thescript, showing output:false, user:“root”}
execute thetask on x
set num to num + 1 as text
end repeat
end tell

I now need a way to handle the workgroup selection window that comes up for network users who are members of more than one workgroup.

I am not sure if this is something that can be done in the same script or if it should be a second script alltogether.

This is what i tried as a second script, it does select the student workgroup from the list of workgroups but sending the return key does not proceed past this screen. I somehow need to have the login button pressed.

Please help.

tell application “Remote Desktop”
set theComputers to the selection
repeat with x in theComputers
set thescript to “osascript -e ‘tell application "System Events"’ -e ‘keystroke "student"’ -e ‘delay 0.5’ -e ‘keystroke return’ -e ‘end tell’”
set thetask to make new send unix command task with properties {name:“Multigui Login”, script:thescript, showing output:false, user:“root”}
execute thetask on x
end repeat
end tell