Custom Control Sequences

Enables defining a custom control sequence.

class CustomControlSequenceMonitor(connection: iterm2.connection.Connection, identity: str, regex: str, session_id: Optional[str] = None)

Registers a handler for a custom control sequence.

  • connection – The connection to iTerm2.

  • identity – A string that must be provided as the sender identity in the control sequence. This is a shared secret, to make it harder to invoke control sequences without permission.

  • regex – A regular expression. It will be used to search the payload. If it matches, the resulting re.Match is returned from async_get().

  • session_id – The session ID to monitor, or None to mean monitor all sessions (including those not yet created).


async with iterm2.CustomControlSequenceMonitor(
        r'^create-window$') as mon:
    while True:
        match = await mon.async_get()
        await iterm2.Window.async_create(connection)
async async_get()Match

Blocks until a matching control sequence is returned.


A re.Match produced by searching the control sequence’s payload with the regular expression this object was initialized with.

Indices and tables