通过脚本使用 zsh 和 iterm2 打开 2 个屏幕

USe*_*299 1 zsh iterm iterm2 oh-my-zsh

我想要一个脚本,它能够通过脚本打开 1 个 iterm 选项卡,其中包含 2 个分屏。

是否有可能或者我应该为此安装一个额外的库?

0st*_*ne0 6

是的!无需任何外部库即可实现这一点。

使用osascript向 Iterm “发送”命令,这个简单的脚本应该打开一个新选项卡,将其拆分并调用一些命令;

#!/bin/bash

osascript<<EOF
    tell application "iTerm"
        activate
        select first window

        # Create new tab
        tell current window
            create tab with default profile
        end tell

        # Split pane
        tell current session of current window
            split vertically with default profile
        end tell

        # Run command in Pane-1
        tell first session of current tab of current window
            write text "cd /tmp"
            write text "pwd"
        end tell

        # Run command in Pane-2
        tell second session of current tab of current window
            write text "echo Second tab!;"
        end tell
    end tell
EOF
Run Code Online (Sandbox Code Playgroud)

脚本的屏幕录制 ( .gif)