Run a command in a new tab in terminal

applescript, command-line, macos, shell, terminal

Solution

tell application "Terminal"
    activate
    tell application "System Events"
        keystroke "t" using {command down}
    end tell
    do script "echo hello" in selected tab of the front window
end tell

Problem

I'm trying to write a script that could run several commands in several tabs in the terminal. I found a lot of informations about it, but it doesn't work as I want it to. So I probably need AppleScript. • This code run a command in a new window: ``` tell app "Terminal" do script "echo hello" end tell ``` • And this one open a new tab ``` tell application "Terminal" activate tell application "System Events" keystroke "t" using {command down} end tell end tell ``` But I didn't figured out how to "mix" them. Any idea ?

Original source