0

I´m opening a ssh connection to an Ubuntu Box with applescript. How can I provide the sudoer password asked by apt:

tell application "Terminal"
        set currentTab to do script ("ssh -p" & pnumber & " " & user & "@localhost;")
        delay 2
        do script ("sudo apt-get update") in currentTab

        -- start provide here password for sudo
        -- this ends in keystroke cannot be read
        keystroke "password"
        keystroke return
        -- end provide password

        do script ("exit;") in currentTab
    end tell
Anatol
  • 1,923
  • 6
  • 26
  • 55
  • possible duplicate of [Sending commands and strings to Terminal.app with Applescript](http://stackoverflow.com/questions/1870270/sending-commands-and-strings-to-terminal-app-with-applescript) – Anatol Jan 31 '15 at 16:11

2 Answers2

2
try
    set resultText to (do shell script "apt-get update" with administrator privileges)
on error e number n 
    tell application (path to frontmost application as text )
        display alert "Something went wrong: " & e & " nr: " & n
    end tell
    error number -128
end try
tell application (path to frontmost application as text)
    display alert resultText
end tell

You'll have to add the full path to apt-get in the do shell script. If you insist of running it in the terminal, then you'll have to write an expect script.

McUsr
  • 1,400
  • 13
  • 10
0

No need for password. Setup a secure RSA key and you will never have to do it again. Then your Applescript will run without a password.

https://help.ubuntu.com/community/SSH/OpenSSH/Keys