【问题标题】:Running shell commands in ITerm2 without tab closing after completion在 ITerm2 中运行 shell 命令,完成后不关闭选项卡
【发布时间】:2016-10-24 15:04:57
【问题描述】:

可能是我弄错了一个小的语法问题,但在 ITerm2 documentation 中找不到解决方案。我想创建一个applescript,它打开一个带有三个选项卡的ITerm 窗口,每个选项卡都运行各种shell 命令(ls、cd、echo 等),在这些命令运行后剩余的选项卡保持打开状态。打开的选项卡部分工作正常,但似乎只要命令运行,选项卡就会关闭(如果我不提供任何命令,选项卡将保持打开状态。)对于我的脚本:

tell application "iTerm2"
  create window with default profile
  tell current window
     create tab with default profile command "echo abc"
     create tab with default profile
  end tell
end tell

我应该放什么而不是“echo abc”,以便 echo 命令将在选项卡中运行,但留给我一个光标让我输入更多命令,而不是随后立即关闭选项卡?

【问题讨论】:

    标签: shell iterm2 iterm


    【解决方案1】:

    不要使用create tab ... command,而是使用单独的write text 命令。例如,这是我用来打开终端到特定目录的脚本:

    tell application "iTerm"
      create window with default profile
      tell current session of current window
        write text "cd " & directory & "; clear"
      end tell
    end tell
    

    【讨论】:

      【解决方案2】:

      使用 whereswalden 建议的“写文本”,我选择了以下方法,效果很好:

      tell application "iTerm2"
        create window with default profile
        tell current window
            tell current session
               write text "echo abc"
            end tell
      
            create tab with default profile
            tell current session
               write text "ls -la"
            end tell
      
            create tab with default profile
            tell current session
                write text "cd mydir"
            end tell
        end tell
      end tell
      

      【讨论】:

        猜你喜欢
        • 2016-12-14
        • 2012-06-12
        • 1970-01-01
        • 2018-12-03
        • 2017-01-07
        • 2010-10-08
        • 2023-03-03
        • 2010-09-30
        • 2011-08-06
        相关资源
        最近更新 更多