Mass login in OS X

Poseiden
New Contributor III

Hey everyone,

I'm trying to mass login into 30 machines via Casper or ARD. The machines are sitting at the login window waiting for a username and password.

I'm currently trying this, but it never logs in. Can someone help me with this?

osascript -e 'tell application "System Events" to keystroke "LOGIN_NAME"'; 
osascript -e 'tell application "System Events" to keystroke tab'; 
osascript -e 'tell application "System Events" to delay 0.5'; 
osascript -e 'tell application "System Events" to keystroke "PASSWORDHERE"'; 
osascript -e 'tell application "System Events" to delay 0.5'; 
osascript -e 'tell application "System Events" to keystroke return'

Thank you all very much.

1 ACCEPTED SOLUTION

MacW0lf
New Contributor II

Try the following and run as root:

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 tab"
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"

View solution in original post

22 REPLIES 22

davidacland
Honored Contributor II

I use exactly the same code. Should be ok, just need to make sure you send it as root and the macs are tabbed into the first text field (username). Give them a restart if they're not there.

Poseiden
New Contributor III

@davidacland

I didn't think of that tabbed part. I'll them all a restart and try again on Monday! I'll report back, thanks!

bhoumikb
New Contributor III

How about trying following? remove "" from the script.

osascript -e 'tell application "System Events" to keystroke "LOGIN_NAME"';
osascript -e 'tell application "System Events" to keystroke tab';
osascript -e 'tell application "System Events" to delay 0.5';
osascript -e 'tell application "System Events" to keystroke "PASSWORDHERE"';
osascript -e 'tell application "System Events" to delay 0.5';
osascript -e 'tell application "System Events" to keystroke return'

Poseiden
New Contributor III

@davidacland @bhoumikb

Thanks guys.

Right now it fails at hitting return at the end. It fills in the username/password but doesn't continue. I've tried "return" and sleep 2 with no results.

The error:

Script result: 36:56: execution error: An error of type -10810 has occurred. (-10810)
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
36:49: execution error: System Events got an error: Application isn’t running. (-600)
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
_RegisterApplication(), FAILED TO establish the default connection to the WindowServer, _CGSDefaultConnection() is NULL.
/Library/Application Support/JAMF/tmp/Mass Login 2: line 6: unexpected EOF while looking for matching `''
/Library/Application Support/JAMF/tmp/Mass Login 2: line 7: syntax error: unexpected end of file

tcam
Contributor

are the client computers running 10.10?

MacW0lf
New Contributor II

Try the following and run as root:

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 tab"
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"

Poseiden
New Contributor III

@tcam Yup, OS X 10.10.4

@rklassen

Thank you very much, worked like a charm!

SGill
Contributor III

Awesomely useful…thanks you guys as always!

snewmantech
New Contributor

Not working for me on 10.10.4. Does not input the user name

46:47: syntax error: Expected “given”, “in”, “of”, expression, “with”, “without”, other parameter name, etc. but found unknown token. (-2741)

stephaniemm77
Contributor II

anyone have an update for this, it no longer seems to work with newest version of OSX El Capitan.

stephaniemm77
Contributor II


This is the error I am getting.

SGill
Contributor III

It errored out for me too in El Cap, but then works anyways...

The trick (for my environment anyways) is that you have to send it right after the computer has been restarted else the cursor isn't in the right location for the script to work...

joshuasee
Contributor III

Adding these before the rest of the script should help avoid the "cursor isn't in the right location" problem:

osascript -e 'tell app "SecurityAgent" to activate'
sleep 1;

I also add these lines after, so if the cursor is in the wrong field the password isn't left visible to all and sundry. If login is successful, they have no effect.

osascript -e 'tell app "System Events" to keystroke tab'
osascript -e 'tell app "System Events" to keystroke (ASCII character 8) using {option down}'

jhuls
Contributor III

Interesting...I never would have thought that this could be done. It sounds like a security issue waiting to happen.

SGill
Contributor III

Like everything else, you have to careful who you give access to what. Think this one is root-only, but haven't tested that.

stephaniemm77
Contributor II

Ive been using this command for some time, unfortunately its not working in 10.14 anymore....anyone have an update?

CapU
Contributor III

I just used this the other day. The tech I was working with was amazed.

osascript <<EOF tell application "System Events" keystroke "username here" keystroke tab delay 0.5 keystroke "Password here" delay 0.5 keystroke return keystroke return end tell EOF

Nix4Life
Valued Contributor

stephaniemm77
Contributor II

This isnt working for me for some reason...I am getting this error
43:44: syntax error: Expected “given”, “in”, “of”, expression, “with”, “without”, other parameter name, etc. but found unknown token. (-2741)

annabarsu
New Contributor

Has anyone managed to find a solution? It used to work just fine for me but after a Mojave update it just hangs and eventually times out in ARD. Anyone?

stephaniemm77
Contributor II

@annabarsu same! I love this command so sad it doesn't work anymore

crbeck
Contributor

@annabarsu @stephaniemm77

I'm still using this with Mojave.

osascript -e 'tell application "System Events"' -e 'keystroke "username"' -e 'keystroke return'  -e 'delay 0.5' -e 'keystroke "password"' -e 'delay 0.5' -e 'keystroke return' -e 'end tell'

With Mojave you have to create a Privacy Preferences Policy Control profile to give ARD access to System Events.

I think this is all you need to set if you use Jamf's PPPC Utility, just click the plus under Apple Events to choose System Events. I ended up setting more permissions than necessary for ARDAgent so you may need to test. ARDAgent's path is /System/Library/CoreServices/RemoteManagement/ARDAgent.app if you need to find it. Upload the profile you create to your Jamf Pro server and scope it out to your Mojave Macs.

d05914779b294ce7a63922ffd264b33a

Just make sure the computers have the cursor in the username field and you run command as user root.