Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

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)