在终端的新选项卡中运行命令

Coh*_*ars 4 macos shell terminal command-line applescript

我正在尝试编写一个可以在终端的多个选项卡中运行多个命令的脚本.我发现了很多关于它的信息,但它并不像我想要的那样工作.所以我可能需要AppleScript.

•此代码在新窗口中运行命令:

tell app "Terminal"
   do script "echo hello"
end tell
Run Code Online (Sandbox Code Playgroud)

•这一个打开一个新选项卡

tell application "Terminal"
  activate
  tell application "System Events"
    keystroke "t" using {command down}
  end tell
end tell
Run Code Online (Sandbox Code Playgroud)

但我没想出如何"混合"它们.任何的想法 ?

Gor*_*son 5

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
Run Code Online (Sandbox Code Playgroud)