使用AppleScript编辑器在终端中输入多个命令

时间:2013-08-29 19:18:46

标签: terminal applescript

所以我正在尝试编写一个简单的脚本,打开终端,将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

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

3 个答案:

答案 0 :(得分:8)

尝试:

tell application "Terminal"
    reopen
    activate
    do script "echo \"commmand one\"" in window 1
    do script "echo \"commmand two\"" in window 1
end tell

答案 1 :(得分:1)

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

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

我使用&符号演示连接,以防“echo \”命令一个\“”是一个变量。

答案 2 :(得分: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