I’m writing a script that will open a remote server, enter my password, and then use the “echo” command to send a string to a file. After I send the command, the script uses the “ls” command on the server to see whether the file has in fact been written. Is there any way that AppleScript can see the result of the “ls” command and set that as an AppleScript variable?
Here is the script, edited for privacy:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
display dialog "Enter the string:" default answer ""
set theString to text returned of result
display dialog "Enter remote password:" default answer "" with hidden answer
set serverPassword to text returned of result
tell application "Terminal"
set ServerAddress to "sftp.remote.server.com"
set ServerUserName to "whoknkows"
activate
set currentTab to do script ("ssh " & ServerUserName & "@" & ServerAddress & ";")
delay 2
do script (serverPassword) in currentTab
delay 2
do script ("cd public_html") in currentTab
delay 1
do script ("echo a>" & theString) in currentTab
delay 2
do script ("ls " & theString) in currentTab
end tell
The login stuff is modified from a StackOverflow post. (I haven’t tested whether the semi-colon at the end of the first remote command is needed there, or needed in all commands.) And I know this is crude and mostly incompetent, but it works to let me know whether theString got echoed to a file, but it would be nice to have a dialog pop up to tell me whether it succeeded or failed, by testing the result of the “ls” command.
Probably there’s a much better way to do this anyway, and I’ll be grateful for any help.