How to login many iMacs at once using Apple Remote Desktop

The Modern Language Lab in Robertson Library has a fleet of 30 iMac computers that can be managed by the (dreamy) Apple Remote Desktop management application. From the instructor machine at the head of the room you can install software, observe, control and even issue command line commands on any or all of the machines in the lab.

When it came time to install Minecraft on all of these machines for our Open Minecraft Lab last Saturday we ran into the problem of the MinecraftEdu installer not being a bona fide Apple install package, so the software-installing magic of Remote Desktop couldn’t be used. Instead I needed to copy the JAR file onto each desktop and then have particpants double-click on it to start the install process.

This was fine, except for the fact that you can’t use Remote Desktop to copy files to iMacs that aren’t already logged in, so I needed to wait for each participant to login (the username and password are both langlabXXX where XXX is the number assigned to each machine, and both are pasted on a label on the front of the machine). What I really wanted, to make things go more smooth, was a way to log in all of the machines before we started, copy the file, and be ready to go out of the gate. Turns out that I could use the command line-sending magic of Remote Desktop to achieve this:

MYIP=`ifconfig en0 | grep inet | grep -v inet6 | awk '{print $2}' | cut -f4 -d.`
echo $MYIP

osascript <tell application "System Events"
keystroke "langlab$MYIP"
keystroke return
delay 0.5
keystroke "langlab$MYIP"
delay 0.5
keystroke return
keystroke return
end tell
EOF

The first part of the code gets the last segment of the IP address for the machine where the script is running – so if the IP address is 137.149.131.136 the returns 136 – as that’s the number assigned to each machine and is the XXX part of the username and password.

The second section of the code uses the osascript command to send Applescript to the machine, essentially “typing in” the username and password and pressing return after each.

This works well, and can be run on all machines at once simply by selecting the machines in question from the Remote Desktop dashboard.

The only weak point comes if any given machine doesn’t have focus on the username field, which is where the Applescript assumes there is focus; I haven’t found a workaround for this yet.