如何用applescript将文本写入iterm2会话?

时间:2018-01-25 04:59:46

标签: applescript iterm2

我正在尝试为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

2 个答案:

答案 0 :(得分:4)

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

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

答案 1 :(得分:0)

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

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