Open terminal and run a command from automator to open two tabs and run a command

Jake McAllister picture Jake McAllister · Nov 13, 2015 · Viewed 12.8k times · Source

What I want to do is run an automator script. Where what happens is it opens terminal with two tabs and each tab and ssh onto [email protected] and root@[email protected]; how would you do this?

Answer

Chris Page picture Chris Page · Nov 28, 2015

You can use the Run AppleScript action to run a script like:

on run {input, parameters}

    tell application "Terminal"
        activate
        do script "ssh [email protected]"
        do script "ssh [email protected]"
    end tell

    return input
end run

Terminal’s do script command creates a new terminal window and sends the given command string to the shell. Note that if you want to send additional commands to the same terminal, store the result of the do script command in a variable—it will be a reference to the terminal that was created and you can use it with the in parameter of the do script command to send more commands to that terminal.