SOLVED Need Applescript To Give PW When Terminal Asks

Joined
Sep 13, 2020
Messages
2
Reaction score
0
Hi, I am trying to write an Applescript that opens Terminal, then logs in to another machine with ssh [email protected], then types in the password when it asks. NOTE: I can manually open Terminal and type in ssh [email protected] and it asks for password, I type it in, and it is connected. The problem is I can' get Applescript to do this same thing in Terminal? I can't get Applescript to automatically answer with a typed password?
Here is what I tried:
tell application "Terminal"
activate
do script "ssh [email protected]"
delay 6
do script "password"
*insert some other commands after logged in*

The Terminal opens and does try to ssh into the machine, but when it is asked for a password, Applescript doesn't type it in?

Does anyone know how to get Applescript to type in the password when it is requested by the ssh response?
I KNOW it CAN be done in Applescript/Terminal, because I can manually type it in and it works. I just can't get Applescript to do the same thing.........
-Thanks
 
Joined
Sep 13, 2020
Messages
2
Reaction score
0
I figured this out, after waaay too much time trying.
I hope it helps someone else. Here is what works:
Screen Shot 2020-09-13 at 6.00.57 PM.png
 
Joined
Jan 25, 2017
Messages
1,266
Reaction score
100
Apologies, I did not see this until this morning. Your solution is very similar to a script I use to log in to my server, then open and log in to mysql.

Code:
tell application "Terminal"
    set currentTab to do script ("ssh [email protected];")
    delay 4
    do script ("password") in currentTab               --------------Login password
    delay 1
    do script ("sudo mysql -u steve -p") in currentTab          -----Login to mysql
    delay 1
    do script ("password") in currentTab                -------------Login password (for sudo command)
    delay 1
    do script ("password") in currentTab                   ----------mysql password
end tell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top