【问题标题】:Using AppleScript editor to input multiple commands in terminal使用 AppleScript 编辑器在终端中输入多个命令
【发布时间】:2013-09-02 09:11:12
【问题描述】:

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

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

【问题讨论】:

    标签: terminal applescript


    【解决方案1】:

    试试:

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

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        【解决方案3】:
        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多