Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using AppleScript editor to input multiple commands in terminal

So i'm trying to write a simple script that opens terminal, ssh onto a server and does stuff while it's there.

tell application "Terminal"
    Activate
    do script "cd documents"
    delay 2
    do script "ssh private key user@server"
    delay 6
    do script "while true; do curl..."
end tell

How do i get it all in one terminal tab? Currently it opens separate windows for each command

like image 857
samalam Avatar asked Aug 29 '13 19:08

samalam


People also ask

How do you edit AppleScript?

EDITING A SCRIPT You are going to edit it so that it can actually open the fragment editors of each of the selected sequences. From the AppleScript Editor File menu choose Open and locate the script called "Edit this Script" inside the Sample Data's AppleScript folder. Select the script and click the Openbutton.

How do I run AppleScript on Mac?

In the Script Editor app on your Mac, click the Run button in the toolbar, or press Command-R, to execute the commands in your script.


2 Answers

Try:

tell application "Terminal"
    reopen
    activate
    do script "echo \"commmand one\"" in window 1
    do script "echo \"commmand two\"" in window 1
end tell
like image 154
adayzdone Avatar answered Nov 08 '22 12:11

adayzdone


Another way is to use semicolon to concatenate two commands, like this:

tell application "Terminal"
    activate
    do script "echo \"commmand one\"" & " ; " & "echo \"commmand two\""
end tell

I used & symbol to demo concatenation in case the "echo \"commmand one\"" is a variable.

like image 41
Johnny Wong Avatar answered Nov 08 '22 12:11

Johnny Wong