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

sla*_*r98 2 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
Run Code Online (Sandbox Code Playgroud)

sla*_*r98 5

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

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
Run Code Online (Sandbox Code Playgroud)