Terminal Commands to "keystroke" no longer works

Discussion in 'OS X Mavericks (10.9)' started by carterx, Jul 16, 2014.

  1. carterx macrumors member

    carterx

    Joined:
    Dec 4, 2006
    #1
    I've been using this for some years now with ARD to log into whole labs when we are doing work on them. As you can see below I would use this command to have an entire lab login for me. As of OS X Mavericks it would see you cannot use osascript -e? Can someone help me create a method that works with Mavericks that does the following?

    Code:
    osascript -e 'tell application "System Events" to keystroke “xxxxusernamexxxx"'; \
    osascript -e 'tell application "System Events" to delay 1.0'; \
    osascript -e 'tell application "System Events" to keystroke return'
    osascript -e 'tell application "System Events" to delay 4.0'; \
    osascript -e 'tell application "System Events" to keystroke “xxxxpasswordxxxx"'; \
    osascript -e 'tell application "System Events" to delay 1.0'; \
    osascript -e 'tell application "System Events" to keystroke return’
    Thank you!
     
  2. chrfr macrumors 603

    Joined:
    Jul 11, 2009
    #2
    I use that exact script, with different timings, on a regular basis with 10.9.x systems in a lab. It works fine, though you need to be sure the systems are set to type the username and password in, not select from a list of users.
    Sometimes the username field will not be active on a computer that's been up for a while, so usually I'll reboot machines first before running the script.
    EDIT: in my script, the second keystroke is Tab, not Return.
    Also, in the code you pasted, you have a smart quote before the username and password fields.
     
  3. w0lf, Jul 16, 2014
    Last edited: Jul 16, 2014

    w0lf macrumors 65816

    w0lf

    Joined:
    Feb 16, 2013
    Location:
    USA
    #3
    I think automator now uses smart quotes by default.

    Right click and uncheck all the smart stuff under substitutions.
     
  4. zeroff macrumors newbie

    Joined:
    Aug 28, 2014
    #4
    I found this somewhere on the Net. I've been using it trough ARD "Send UNIX Command...".

    To works, the login window must be set to type the username and password in, not select from a list of users.

    /usr/bin/osascript <<EndOfMyScript
    tell application "System Events"
    keystroke "user_name"
    delay 3.0
    keystroke return
    delay 3.0
    keystroke "user_password"
    delay 3.0
    keystroke return
    delay 3.0
    end tell
    EndOfMyScript

    ----
    NOTE: sometimes Mavericks put the cursor in the "Password" field instead in the "User Name", which brakes the script. To fix it, just include one more line before "keystroke "user_name"". It will put the cursor back in the "Name":

    /usr/bin/osascript <<EndOfMyScript
    tell application "System Events"
    keystroke tab
    keystroke "user_name"
    .....

    Or you can run separate script, before the main one:

    /usr/bin/osascript <<EndOfMyScript
    tell application "System Events"
    keystroke tab
    end tell
    EndOfMyScript

    Good luck!
     

Share This Page