【问题标题】:How to write text to a iterm2 session in applescript?如何在applescript中将文本写入iterm2会话?
【发布时间】:2018-01-25 04:59:46
【问题描述】:

我正在尝试为 iTerm2 创建一个脚本,该脚本将创建一个会话(通过拆分),然后将文本输入到新创建的会话中。如何激活新创建的会话?

tell application "iTerm"
    tell current session of current window
        split horizontally with default profile
    end tell

    -- Here is what I need help with?
    set _new_session to <what goes here> of current window
    tell _new_session
        write text "ls"
    end tell
end tell

【问题讨论】:

    标签: applescript iterm2


    【解决方案1】:

    当然,我在发布我的问题后不久就想到了这一点。要获得会话,您必须通过选项卡,我没有这样做。这是一个工作示例:

    tell application "iTerm"
        tell current session of current window
            split horizontally with default profile
        end tell
    
        tell current tab of current window
            set _new_session to last item of sessions
        end tell
    
        tell _new_session
            select
            write text "ls"
        end tell
    end tell
    

    【讨论】:

      【解决方案2】:

      如果您的最终目标是在 shell 上执行脚本,您也可以使用

      set sc to "ping google.com"
      do shell script (quoted form of sc)
      

      【讨论】:

      • 我的最终目标是构建一个脚本,该脚本将打开一个终端并创建一个打开终端编辑器(微型)的第二个会话。然后当脚本再次运行时,它将检查编辑器会话是否存在,如果存在,它将打开我发送的文件。
      • 所以你到底需要打开一个文件吗?为什么需要一个终端会话?
      • 我正在编写一个脚本以在现有终端编辑器中打开一个文件,该编辑器已经在另一个窗格中打开。
      • 你想在 shell 中用 nano 之类的编辑器打开它,还是只是一个打开的命令来启动第三方软件?
      • 在外壳(单独的窗格)中,我正在用micro 做这件事。当然,我希望它可以与任何终端编辑器(nano、emacs 等)一起使用。它将使我能够维护类似于使用单个实例编辑器(例如 atom)但完全在终端 shell 中的工作流程。理想情况下,它也可以在登录到远程会话时工作。只是我正在玩的东西,还没有花很多时间,但我认为它会起作用。感谢您的关注。
      猜你喜欢
      • 2019-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多