Skip to main content

Is there a way—via Apple, shell script, or third party software—where multiple user accounts on a Macintosh computer can be automatically logged in, then out, like in a script. For example, account #1 is logged in, then out, then log into account #2, log out, then log into account #3, etc?



(Yes, I am taking into consideration the security issue of such a method needing both username and password in order for authentication to occur. For purposes of discussion, assume that this is for a test environment where it is not an issue.)

Hey Sean,



At a previous job I wrote an apple script, that I used inside my imaging postflight bash script. It looked like this:



#!/bin/bash
#define variables
localaccount="localuser"
localpasswd="1234"

/usr/bin/osascript <<AppleScript
tell application "System Events"
keystroke "$localaccount"
keystroke return
delay 3.0
keystroke "$localpasswd"
delay 3.0
keystroke tab
keystroke return
end tell
AppleScript


This only works at the login window. You could have a list of user names and passwords, and then after logs the user in then kills the login window and logs in the next. now, I cannot remember what I had to do this for, something like a vendor supplied installer could only be installed when a user was actually logged in. So, I scripted this, and then had a postflight script that removed that local user account when finished.



Hope this helps, and of course be weary of storing usernames and passwords in scripts.



Thanks,
Tom


I use a similar method to boot up a 10.7 computer lab for testing purposes:



osascript -e <<EOF 'tell application "System Events"
tell process "SecurityAgent"
set value of text field 1 of window "Login" to "password"
set value of text field 2 of window "Login" to "username"
end tell
tell application "system events" to keystroke return
tell application "system events" to keystroke return
end tell'
EOF


Mine is slightly different as the script above probably needs the active field to be the username one. I just send this little script via ARD.


Reply