home ~ socials ~ projects ~ rss

Trigger An External Process When A New Tab Is Made In iTerm2

February 2023

This is what I use for iterm-image-cycler.

It's a bare bones script for iTerm2 two that triggers and external process.

#!/usr/bin/env python3

import iterm2
import subprocess

async def main(connection):
    async with iterm2.NewSessionMonitor(connection) as mon:
        while True:
            await mon.async_get()
            subprocess.run(['path/to/executable'])
iterm2.run_forever(main)
end of line
Share link:
https://www.alanwsmith.com/en/2l/wy/d6/c5/?trigger-an-external-process-when-a-new-tab-is-made-in-iterm2