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

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

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

Code

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