jacob_salmela cmaBadge
2

Comments

10.7 Lion: remotely log in user via loginwindow

Posted 10/9/12 at 10:52 AM by jacob_salmela

I work at a High School and we need to set up labs for testing. We have a local user account that we need to log in and some testing software to launch. We typically do this to make it easy for the testing coordinators; they just come in and the software is already up. Since I do not want to type the username/password manually on each computer, I want to use a script or command to do this.

In 10.6 I just ran these simple AppleScript commands from ARD or saved it as a script and ran it via Remote:
osascript -e 'tell application "system events" to keystroke "username"'
osascript -e 'tell application "system events" to delay 0.5'
osascript -e 'tell application "system events" to keystroke return'
osascript -e 'tell application "system events" to delay 0.5'
osascript -e 'tell application "system events" to keystroke "password"'
osascript -e 'tell application "system events" to delay 0.5'
osascript -e 'tell application "system events" to keystroke return'

In 10.7, I noticed this no longer worked. So here is what I came up with:
touch /private/var/db/.AccessibilityAPIEnabled
osascript -e <<EOF 'tell application "System Events"
tell process "SecurityAgent"
set value of text field 1 of window "Login" to "testing"
set value of text field 2 of window "Login" to "testing"
end tell
tell application "system events" to keystroke return
tell application "system events" to keystroke return
end tell'
EOF

I am not sure if anyone else would want this or not, but I thought I would just throw it out there.

I have found it useful for setting an entire lab up for testing. Once the user is logged in, I send another command to launch the testing software. Now, when the students show up, they just choose their test and off they go.

2

Comments

Snickasaurus
Posted 10/10/12 at 11:38 PM by Snickasaurus

Thanks for sharing. I'm going to give this a try!

jacob_salmela cmaBadge
Posted 2/17/14 at 9:33 AM by jacob_salmela
Solved Solved

This python script seems to work on 10.6-10.9 with one caveat: the focus of the cursor needs to be in the username field since the script just executes the commands in sequence.

In 10.9, each app has to be enabled for access to assistive devices (such as using osascript to click buttons, which the previous scripts tried to do), so this script just works around that by only entering text and not interacting with any buttons.

Instead of clicking the button, it just tries to press the return key twice to log in to the GUI.

Also, when executing this via ARD, I noticed instead of having the shebang at the beginning of the script, just type python and then the rest of the script.

10.6-10.9 script to login user to the GUI
#!/usr/bin/python
from os import system

cmd = """
osascript -e 'tell application "System Events"
keystroke "username"
keystroke tab
keystroke "password"
keystroke return
keystroke return
end tell'
"""

system(cmd)