Run the command on a new tab in the terminal

I am trying to write a script that could run several commands on several tabs in the terminal. I found a lot of information about this, but it does not work the way I want. So I probably need AppleScript.

β€’ This code launches the command in a new window:

tell app "Terminal"
   do script "echo hello"
end tell

β€’ And this will open a new tab

tell application "Terminal"
  activate
  tell application "System Events"
    keystroke "t" using {command down}
  end tell
end tell

But I did not understand how to "mix" them. Any idea?

+4
source share
1 answer
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
+5
source

Source: https://habr.com/ru/post/1525240/


All Articles