iTerm Module Reference

New in version 0.1.0.

Control iTerm using JXA-like syntax.

Classes:

XAiTermApplication(properties)

A class for managing and interacting with iTerm.app.

XAiTermHotkeyWindow(properties)

A hotkey window of iTerm.app.

XAiTermSession(properties)

A session of iTerm.app.

XAiTermTab(properties)

A tab of iTerm.app.

XAiTermWindow(properties)

A window of iTerm.app.

class PyXA.apps.iTerm.XAiTermApplication(properties)[source]

Bases: XASBApplication

A class for managing and interacting with iTerm.app.

New in version 0.1.0.

Methods:

create_hotkey_window([profile])

Creates a new hotkey window with the given profile.

create_window([profile, command])

Creates a new window with the given profile, executing the specified command upon the window's creation.

invoke_api_expression(expression)

Invokes an expression, such as a registered function.

launch_api_script(script_name[, arguments])

Launches an API script by name, providing it with the given arguments.

request_cookie_and_key(app)

Requests a Python API cookie for the specified application.

Attributes:

current_window

The frontmost window.

frontmost

Whether iTerm is the active application.

name

The name of the application.

version

The version of iTerm.app.

create_hotkey_window(profile: str | None = None) XAiTermHotkeyWindow[source]

Creates a new hotkey window with the given profile.

Parameters:

profile (Union[str, None], optional) – The profile to initialize the window with, defaults to None

Returns:

The newly created hotkey window object

Return type:

XAiTermHotkeyWindow

New in version 0.1.0.

create_window(profile: str | None = None, command: str | None = None) XAiTermWindow[source]

Creates a new window with the given profile, executing the specified command upon the window’s creation.

Parameters:
  • profile (Union[str, None], optional) – The profile to initialize the window with, defaults to None (default profile)

  • command (Union[str, None], optional) – The command to execute, defaults to None

Returns:

The newly created window object

Return type:

XAiTermWindow

New in version 0.1.0.

property current_window: XAiTermWindow

The frontmost window.

property frontmost: bool

Whether iTerm is the active application.

invoke_api_expression(expression: str)[source]

Invokes an expression, such as a registered function.

Parameters:

expression (str) – The expression to invoke

New in version 0.1.0.

launch_api_script(script_name: str, arguments: list[str] | None = None)[source]

Launches an API script by name, providing it with the given arguments.

Parameters:
  • script_name (str) – The name of the script to launch

  • arguments (Union[list[str], None], optional) – The arguments to pass to the script, defaults to None

New in version 0.1.0.

property name: str

The name of the application.

Requests a Python API cookie for the specified application.

Parameters:

app (str) – The app to retrieve an API cookie for

Returns:

The API cookie

Return type:

str

New in version 0.1.0.

property version: str

The version of iTerm.app.

class PyXA.apps.iTerm.XAiTermHotkeyWindow(properties)[source]

Bases: XAiTermWindow

A hotkey window of iTerm.app.

New in version 0.1.0.

Methods:

hide_hotkey_window()

Hides the hotkey window.

reveal_hotkey_window()

Reveals the hotkey window.

toggle_hotkey_window()

Toggles the hotkey window.

hide_hotkey_window()[source]

Hides the hotkey window.

New in version 0.1.0.

reveal_hotkey_window()[source]

Reveals the hotkey window.

New in version 0.1.0.

toggle_hotkey_window()[source]

Toggles the hotkey window.

New in version 0.1.0.

class PyXA.apps.iTerm.XAiTermSession(properties)[source]

Bases: XAObject, XACloseable, XASelectable

A session of iTerm.app.

New in version 0.1.0.

Attributes:

ansi_black_color

ansi_blue_color

ansi_bright_black_color

ansi_bright_blue_color

ansi_bright_cyan_color

ansi_bright_green_color

ansi_bright_magenta_color

ansi_bright_red_color

ansi_bright_white_color

ansi_bright_yellow_color

ansi_cyan_color

ansi_green_color

ansi_magenta_color

ansi_red_color

ansi_white_color

ansi_yellow_color

answerback_string

ENQ Answerback string.

background_color

background_image

The path of the background image file.

bold_color

color_preset

The color preset of the session.

columns

The number of columns in the terminal window.

contents

The currently visible contents of the session.

cursor_color

cursor_text_color

foreground_color

id

The unique identifier of the session.

is_at_shell_prompt

Whether the terminal is at the shell prompt.

is_processing

Whether the session is currently processing.

name

The name of the session.

profile_name

The session's profile name.

rows

The number of rows in the terminal window.

selected_text_color

selection_color

text

The currently visible contents of the session.

transparency

The transparency of the session window.

tty

The current TTY.

underline_color

unique_id

The unique identifier of the session.

use_underline_color

Whether to use a dedicated color for underlining.

Methods:

close()

Closes the session.

set_variable(variable_name, value)

Sets the value of a session variable.

split_horizontally([profile, command])

Splits the session horizontally, instantiating a new session with the specified profile.

split_horizontally_with_default_profile([...])

Splits the session horizontally, instantiating a new session with the default profile.

split_vertically([profile, command])

Splits the session vertically, instantiating a new session with the specified profile.

split_vertically_with_default_profile(command)

Splits the session vertically, instantiating a new session with the default profile.

variable(variable_name)

Returns the value of a session variable with the given name.

write([text, file, add_newline])

Writes a string or file contents to the session.

property ansi_black_color: XAColor
property ansi_blue_color: XAColor
property ansi_bright_black_color: XAColor
property ansi_bright_blue_color: XAColor
property ansi_bright_cyan_color: XAColor
property ansi_bright_green_color: XAColor
property ansi_bright_magenta_color: XAColor
property ansi_bright_red_color: XAColor
property ansi_bright_white_color: XAColor
property ansi_bright_yellow_color: XAColor
property ansi_cyan_color: XAColor
property ansi_green_color: XAColor
property ansi_magenta_color: XAColor
property ansi_red_color: XAColor
property ansi_white_color: XAColor
property ansi_yellow_color: XAColor
property answerback_string: str

ENQ Answerback string.

property background_color: XAColor
property background_image: str

The path of the background image file.

property bold_color: XAColor
close()[source]

Closes the session.

New in version 0.1.0.

property color_preset: str

The color preset of the session.

property columns: int

The number of columns in the terminal window.

property contents: str

The currently visible contents of the session.

property cursor_color: XAColor
property cursor_text_color: XAColor
property foreground_color: XAColor
property id: str

The unique identifier of the session.

property is_at_shell_prompt: bool

Whether the terminal is at the shell prompt.

property is_processing: bool

Whether the session is currently processing.

property name: str

The name of the session.

property profile_name: str

The session’s profile name.

property rows: int

The number of rows in the terminal window.

property selected_text_color: XAColor
property selection_color: XAColor
set_variable(variable_name: str, value: str) str[source]

Sets the value of a session variable.

Parameters:
  • variable_name (str) – The name of the variable to set

  • value (str) – The value to give the variable

Returns:

The new value of the variable

Return type:

str

New in version 0.1.0.

split_horizontally(profile: str | None = None, command: str | None = None)[source]

Splits the session horizontally, instantiating a new session with the specified profile.

Parameters:
  • profile (Union[str, None], optional) – The profile to instantiate the new session with, defaults to None (current profile)

  • command (Union[str, None], optional) – The command to run in the newly created session upon its creation, defaults to None

New in version 0.1.0.

split_horizontally_with_default_profile(command: str | None = None)[source]

Splits the session horizontally, instantiating a new session with the default profile.

Parameters:

command (Union[str, None]) – The command to run in the newly created session upon its creation, defaults to None

New in version 0.1.0.

split_vertically(profile: str | None = None, command: str | None = None)[source]

Splits the session vertically, instantiating a new session with the specified profile.

Parameters:
  • profile (Union[str, None], optional) – The profile to instantiate the new session with, defaults to None (current profile)

  • command (Union[str, None], optional) – The command to run in the newly created session upon its creation, defaults to None

New in version 0.1.0.

split_vertically_with_default_profile(command: str | None)[source]

Splits the session vertically, instantiating a new session with the default profile.

Parameters:

command (Union[str, None]) – The command to run in the newly created session upon its creation, defaults to None

New in version 0.1.0.

property text: str

The currently visible contents of the session.

property transparency: float

The transparency of the session window.

property tty: str

The current TTY.

property underline_color: XAColor
property unique_id: str

The unique identifier of the session.

property use_underline_color: bool

Whether to use a dedicated color for underlining.

variable(variable_name: str) str[source]

Returns the value of a session variable with the given name.

Parameters:

variable_name (str) – The name of the variable to retrieve the value on

Returns:

The value of the variable

Return type:

str

New in version 0.1.0.

write(text: str | None = None, file: str | XAPath | None = None, add_newline: bool = True)[source]

Writes a string or file contents to the session.

Parameters:
  • text (Union[str, None], optional) – The text to input into the session, defaults to None

  • file (Union[XABase.XAPath, str, None], optional) – The file whose contents to input into the session, defaults to None

  • add_newline (bool, optional) – Whether to add a new line after inputting the specified content, defaults to True

New in version 0.1.0.

class PyXA.apps.iTerm.XAiTermTab(properties)[source]

Bases: XAObject, XACloseable, XASelectable

A tab of iTerm.app.

New in version 0.1.0.

Methods:

close()

Closes the tab.

move_to(window)

Attributes:

current_session

The current session in a tab.

index

Index of tab in parent tab view control.

close()[source]

Closes the tab.

New in version 0.1.0.

property current_session: XAiTermSession

The current session in a tab.

property index: int

Index of tab in parent tab view control.

move_to(window: XAiTermWindow)[source]
class PyXA.apps.iTerm.XAiTermWindow(properties)[source]

Bases: XASBWindow, XAObject, XASelectable, XACloseable

A window of iTerm.app.

New in version 0.1.0.

Attributes:

alternate_identifier

The alternate unique identifier of the session.

current_session

The current session in a window.

current_tab

The currently selected tab.

frontmost

Whether the window is currently the frontmost iTerm window.

hotkey_window_profile

If the window is a hotkey window, this gives the name of the profile that created the window.

is_hotkey_window

Whether the window is a hotkey window.

position

The position of the window, relative to the upper left corner of the screen.

Methods:

close()

Closes the window.

create_tab([profile, command])

Creates a new tab with the given profile, executing the specified command upon the tab's creation.

property alternate_identifier: str

The alternate unique identifier of the session.

close()[source]

Closes the window.

New in version 0.1.0.

create_tab(profile: str | None = None, command: str | None = None)[source]

Creates a new tab with the given profile, executing the specified command upon the tab’s creation.

Parameters:
  • profile (Union[str, None], optional) – The name of the profile to assign to the tab, if any, defaults to None (default profile)

  • command (Union[str, None], optional) – The command to run in the tab, if any, defaults to None

property current_session: XAiTermSession

The current session in a window.

property current_tab: XAiTermTab

The currently selected tab.

property frontmost: bool

Whether the window is currently the frontmost iTerm window.

property hotkey_window_profile: str

If the window is a hotkey window, this gives the name of the profile that created the window.

property is_hotkey_window: bool

Whether the window is a hotkey window.

property position: tuple[int, int]

The position of the window, relative to the upper left corner of the screen.