Applescript:从调用脚本的窗口拆分窗格



我有以下脚本,尝试垂直分割窗口,并在新窗格中跟踪日志文件。

#!/bin/bash
COMMAND="tail -f log_file"
# Do something important.
sleep 4
# Split the window, and tail logs.
osascript <<-EOF
tell application "iTerm"
    tell current session of current window
        split vertically with default profile command "$COMMAND"
    end tell
end tell
EOF

但是,该脚本分割当前焦点的窗口,而不是脚本正在运行的窗口。

重现问题的步骤:

  1. 打开一个term窗口(比如W1),然后运行这个脚本。
  2. 当脚本执行sleep 4时,打开另一个窗口(例如W2)并保持W2的焦点。
  3. 4秒后,新窗口(即W2)将垂直分割。

如何打开分割窗口从W1,窗口在哪里脚本被调用?

在脚本开始处获取当前会话的ID

在脚本后面,获取与此标识符

对应的会话
#!/bin/bash
myID=$(osascript -e 'tell application "iTerm" to id of current session of current window')
COMMAND="tail -f log_file"
# Do something important.
sleep 4
# Split the window, and tail logs. myID2 is the id of the new session (the split pane)
myID2=$(osascript <<-EOF
tell application "iTerm"
    repeat with w in windows
        repeat with t in tabs of w
            tell (first session of t whose its id = "$myID")
                if exists then return id of (split vertically with default profile command "$COMMAND")
            end tell
        end repeat
    end repeat
end tell
EOF)

相关内容

  • 没有找到相关文章

最新更新