2

I'm currently trying to do something quite odd. I want to automate updates on multiple computers in my office and first I need to open a program and said program has two fields; one for username and another for a password.

Obviously walking around the office to 50 computers and inputting my user and password is quite annoying so what I'd rather do is be able to assign my username and password to variables and then pass those variables to the username and password fields in the program.

So far I can open the program via the remote desktop app on all the machines and I can use osascript to send keystrokes but I want terminal to ask me for the username and password so that I don't save them into my script. Is there an easy way to do this and then tell those variables that I save my pass and username into to be the keystrokes? Thanks!!

  • 1
    By Terminal, are you referring to a shell script, a compiled binary or something else? – grg Sep 6 '14 at 23:01
  • Hey George, I am using a shell script. So far I have written out a script and I basically have every part except for asking for a password and username for the variables. The reason is, once I leave I want the next person to be able to use this same script and have it be pretty fool-proof. – ElRojito Sep 8 '14 at 5:10
3

These lines will prompt for your username and password:

echo -n 'Username: '
read username

echo -n 'Password: '
read -s password #The -s means silent, so your password is not shown in the terminal.

You can then use the variables $username and $password in the rest of your script, like this:

osascript -e 'tell app "System Events" to keystroke "'"$username"'" & tab & "'"$password"'"'

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .