5

所以我正在尝试编写一个简单的脚本来打开终端,ssh 到服务器并在它在那里时做一些事情。

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

如何在一个终端选项卡中获取所有内容?目前它为每个命令打开单独的窗口

4

3 回答 3

10

尝试:

tell application "Terminal"
    reopen
    activate
    do script "echo \"commmand one\"" in window 1
    do script "echo \"commmand two\"" in window 1
end tell
于 2013-08-29T19:28:23.400 回答
2

另一种方法是使用分号连接两个命令,如下所示:

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

我使用&符号来演示连接,以防“echo \"commmand one\"" 是一个变量。

于 2017-08-04T03:01:22.547 回答
0
tell application "Terminal"
    reopen
    activate
    delay 1
    do script "cd ~/Projects" in front window
    do script "ls -al" in front window
    do script "date" in front window

    tell application "System Events" to keystroke "t" using {command down}
    delay 1
    do script "cd ~/Projects/react-app" in front window
    do script "ls -al" in front window
end tell
于 2020-02-01T16:59:33.023 回答