USer22999299
USer22999299

Reputation: 5674

Open 2 screens split with zsh & iterm2 via script

I would like to have a script which would be able to open 1 iterm tab which contains 2 split screens inside via script.

Is it possible or should I install an additional lib for that?

Upvotes: 1

Views: 2153

Answers (1)

0stone0
0stone0

Reputation: 43964

Yes! This is possible without any external libraries.

Using osascript to 'send' commands to Iterm this simple script should open a new tab, split it and call some commands;

#!/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

Screen recording of script (.gif)

Upvotes: 6

Related Questions