Focus

class FocusMonitor(connection: iterm2.connection.Connection)

An asyncio context manager for monitoring keyboard focus changes.

Parameters

connection – A connection to iTerm2.

See also

Example “Persistent MRU Tabs

async async_get_next_update()iterm2.focus.FocusUpdate

When focus changes, returns an update.

Returns

A FocusUpdate object.

Example:

async with iterm2.FocusMonitor(connection) as monitor:
    while True:
        update = await monitor.async_get_next_update()
        if update.selected_tab_changed:
            print("The active tab is now {}".
                format(update.selected_tab_changed.tab_id))
class FocusUpdate(application_active: Optional[iterm2.focus.FocusUpdateApplicationActive] = None, window_changed: Optional[iterm2.focus.FocusUpdateWindowChanged] = None, selected_tab_changed: Optional[iterm2.focus.FocusUpdateSelectedTabChanged] = None, active_session_changed: Optional[iterm2.focus.FocusUpdateActiveSessionChanged] = None)

Describes a change to keyboard focus.

Up to one of application_active, window_changed, selected_tab_changed, or active_session_changed will not be None.

property active_session_changed: Union[None, iterm2.focus.FocusUpdateActiveSessionChanged]
Returns

None if no change to active session, otherwise FocusUpdateActiveSessionChanged.

property application_active: Union[None, iterm2.focus.FocusUpdateApplicationActive]
Returns

None if no change to whether the app is active, otherwise FocusUpdateApplicationActive

property selected_tab_changed: Union[None, iterm2.focus.FocusUpdateSelectedTabChanged]
Returns

None if no change to selected tab, otherwise FocusUpdateSelectedTabChanged.

property window_changed: Union[None, iterm2.focus.FocusUpdateWindowChanged]
Returns

None if no change to the current window, otherwise FocusUpdateWindowChanged.

class FocusUpdateActiveSessionChanged(session_id: str)

Describes a change to the active session within a tab.

property session_id: str

Returns the active session ID within its tab.

Returns

A session ID, which is a string.

class FocusUpdateSelectedTabChanged(tab_id: str)

Describes a change in the selected tab.

property tab_id: str
Returns

A tab ID, which is a string.

class FocusUpdateWindowChanged(window_id: str, event: iterm2.focus.FocusUpdateWindowChanged.Reason)

Describes a change in which window is focused.

property event: Reason

Describes how the window’s focus changed.

Returns

The reason for the update.

property window_id: str
Returns

the window ID of the window that changed.

class FocusUpdateWindowChanged.Reason(value)

Gives the reason for the change

TERMINAL_WINDOW_BECAME_KEY = 0

A terminal window received keyboard focus.

TERMINAL_WINDOW_IS_CURRENT = 1

A terminal window is current but some non-terminal window (such as Preferences) has keyboard focus.

TERMINAL_WINDOW_RESIGNED_KEY = 2

A terminal window no longer has keyboard focus.

class FocusUpdateApplicationActive(active)

Describes a change in whether the application is active.

property application_active: bool
Returns

True if the application is active or False if not.


Indices and tables