Terminal Module Reference

New in version 0.0.1.

Control the macOS Terminal application using JXA-like syntax.

Classes:

XATerminalApplication(properties)

A class for managing and interacting with Messages.app

XATerminalSettingsSet(properties)

A class for managing and interacting with settings sets in Terminal.app.

XATerminalSettingsSetList(properties[, filter])

A wrapper around lists of Terminal settings sets that employs fast enumeration techniques.

XATerminalTab(properties)

A class for managing and interacting with tabs in Terminal.app.

XATerminalTabList(properties[, filter])

A wrapper around lists of Terminal tabs that employs fast enumeration techniques.

XATerminalWindow(properties)

A class for managing and interacting with windows in Terminal.app.

class PyXA.apps.Terminal.XATerminalApplication(properties)[source]

Bases: XASBApplication, XACanOpenPath

A class for managing and interacting with Messages.app

New in version 0.0.1.

Attributes:

current_tab

The currently active Terminal tab.

default_settings

The settings set used for new windows.

frontmost

Whether Terminal is the active application.

name

The name of the application.

startup_settings

The settings set used for the window created on application startup.

version

The version of Terminal.app.

Methods:

do_script(script[, window_tab, return_result])

Executes a Terminal script in the specified window or tab.

settings_sets([filter])

Returns a list of settings sets, as PyXA-wrapped objects, matching the given filter.

property current_tab: XATerminalTab

The currently active Terminal tab.

property default_settings: XATerminalSettingsSet

The settings set used for new windows.

do_script(script: str, window_tab: XATerminalWindow | XATerminalTab | None = None, return_result: bool = False) XATerminalApplication | Dict[str, str][source]

Executes a Terminal script in the specified window or tab.

If no window or tab is provided, the script will run in a new tab of the frontmost window. If return_result is True, the script will be run in a new tab no regardless of the value of window_tab.

Parameters:
  • script (str) – The script to execute.

  • window_tab (Union[XATerminalWindow, XATerminalTab], optional) – The window or tab to execute the script in, defaults to None

  • return_result (bool, optional) – Whether to return the result of script execution, defaults to False

Returns:

A reference to the Terminal application object, or the result of script execution.

Return type:

Union[XATerminalApplication, Dict[str, str]]

Changed in version 0.0.9: Now optionally returns the script execution result.

New in version 0.0.1.

property frontmost: bool

Whether Terminal is the active application.

property name: str

The name of the application.

settings_sets(filter: dict | None = None) XATerminalSettingsSetList | None[source]

Returns a list of settings sets, as PyXA-wrapped objects, matching the given filter.

Parameters:

filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned settings sets will have, or None

Returns:

The list of settings sets

Return type:

XATerminalSettingsSetList

New in version 0.0.7.

property startup_settings: XATerminalSettingsSet

The settings set used for the window created on application startup.

property version: str

The version of Terminal.app.

class PyXA.apps.Terminal.XATerminalSettingsSet(properties)[source]

Bases: XAObject, XAClipboardCodable

A class for managing and interacting with settings sets in Terminal.app.

New in version 0.0.1.

Attributes:

background_color

The background color for the tab.

bold_text_color

The bold text color for the tab.

clean_commands

The processes which will be ignored when checking whether a tab can be closed without showing a prompt.

cursor_color

The cursor color for the tab.

custom_title

The tab's custom title.

font_antialiasing

Whether the font used to display the tab's contents is antialiased.

font_name

The name of the font used to display the tab's contents.

font_size

The size of the font used to display the tab's contents.

id

The unique identifier of the settings set.

name

The name of the settings set.

normal_text_color

The normal text color for the tab.

number_of_columns

The number of columns displayed in the tab.

number_of_rows

The number of rows displayed in the tab.

title_displays_custom_title

Whether the title contains a custom title.

title_displays_device_name

Whether the title contains the device name.

title_displays_settings_name

Whether the title contains the settings set name.

title_displays_shell_path

Whether the title contains the shell path.

title_displays_window_size

Whether the title contains the tab's size, in rows and columns.

Methods:

get_clipboard_representation()

Gets a clipboard-codable representation of the settings set.

property background_color: XAColor

The background color for the tab.

property bold_text_color: XAColor

The bold text color for the tab.

property clean_commands: list[str]

The processes which will be ignored when checking whether a tab can be closed without showing a prompt.

property cursor_color: XAColor

The cursor color for the tab.

property custom_title: str

The tab’s custom title.

property font_antialiasing: bool

Whether the font used to display the tab’s contents is antialiased.

property font_name: str

The name of the font used to display the tab’s contents.

property font_size: int

The size of the font used to display the tab’s contents.

get_clipboard_representation() str[source]

Gets a clipboard-codable representation of the settings set.

When the clipboard content is set to a settings set, the setting set’s name is added to the clipboard.

Returns:

The setting set’s name

Return type:

str

New in version 0.0.8.

property id: int

The unique identifier of the settings set.

property name: str

The name of the settings set.

property normal_text_color: XAColor

The normal text color for the tab.

property number_of_columns: int

The number of columns displayed in the tab.

property number_of_rows: int

The number of rows displayed in the tab.

property title_displays_custom_title: bool

Whether the title contains a custom title.

property title_displays_device_name: bool

Whether the title contains the device name.

property title_displays_settings_name: bool

Whether the title contains the settings set name.

property title_displays_shell_path: bool

Whether the title contains the shell path.

property title_displays_window_size: bool

Whether the title contains the tab’s size, in rows and columns.

class PyXA.apps.Terminal.XATerminalSettingsSetList(properties: dict, filter: dict | None = None)[source]

Bases: XAList, XAClipboardCodable

A wrapper around lists of Terminal settings sets that employs fast enumeration techniques.

All properties of settings sets can be called as methods on the wrapped list, returning a list containing each settings set’s value for the property.

New in version 0.0.7.

Methods:

background_color()

bold_text_color()

by_background_color(background_color)

by_bold_text_color(bold_text_color)

by_clean_commands(clean_commands)

by_cursor_color(cursor_color)

by_custom_title(custom_title)

by_font_antialiasing(font_antialiasing)

by_font_name(font_name)

by_font_size(font_size)

by_id(id)

by_name(name)

by_normal_text_color(normal_text_color)

by_number_of_columns(number_of_columns)

by_number_of_rows(number_of_rows)

by_title_displays_custom_title(...)

by_title_displays_device_name(...)

by_title_displays_settings_name(...)

by_title_displays_shell_path(...)

by_title_displays_window_size(...)

clean_commands()

cursor_color()

custom_title()

font_antialiasing()

font_name()

font_size()

get_clipboard_representation()

Gets a clipboard-codable representation of each settings set in the list.

id()

name()

normal_text_color()

number_of_columns()

number_of_rows()

title_displays_custom_title()

title_displays_device_name()

title_displays_settings_name()

title_displays_shell_path()

title_displays_window_size()

background_color() list[XAColor][source]
bold_text_color() list[XAColor][source]
by_background_color(background_color: XAColor) XATerminalSettingsSet | None[source]
by_bold_text_color(bold_text_color: XAColor) XATerminalSettingsSet | None[source]
by_clean_commands(clean_commands: list[str]) XATerminalSettingsSet | None[source]
by_cursor_color(cursor_color: XAColor) XATerminalSettingsSet | None[source]
by_custom_title(custom_title: str) XATerminalSettingsSet | None[source]
by_font_antialiasing(font_antialiasing: bool) XATerminalSettingsSet | None[source]
by_font_name(font_name: str) XATerminalSettingsSet | None[source]
by_font_size(font_size: int) XATerminalSettingsSet | None[source]
by_id(id: int) XATerminalSettingsSet | None[source]
by_name(name: str) XATerminalSettingsSet | None[source]
by_normal_text_color(normal_text_color: XAColor) XATerminalSettingsSet | None[source]
by_number_of_columns(number_of_columns: int) XATerminalSettingsSet | None[source]
by_number_of_rows(number_of_rows: int) XATerminalSettingsSet | None[source]
by_title_displays_custom_title(title_displays_custom_title: bool) XATerminalSettingsSet | None[source]
by_title_displays_device_name(title_displays_device_name: bool) XATerminalSettingsSet | None[source]
by_title_displays_settings_name(title_displays_settings_name: bool) XATerminalSettingsSet | None[source]
by_title_displays_shell_path(title_displays_shell_path: bool) XATerminalSettingsSet | None[source]
by_title_displays_window_size(title_displays_window_size: bool) XATerminalSettingsSet | None[source]
clean_commands() list[list[str]][source]
cursor_color() list[XAColor][source]
custom_title() list[str][source]
font_antialiasing() list[bool][source]
font_name() list[str][source]
font_size() list[int][source]
get_clipboard_representation() list[str][source]

Gets a clipboard-codable representation of each settings set in the list.

When the clipboard content is set to a list of settings sets, each setting set’s name is added to the clipboard.

Returns:

The list of setting set names

Return type:

list[str]

New in version 0.0.8.

id() list[int][source]
name() list[str][source]
normal_text_color() list[XAColor][source]
number_of_columns() list[int][source]
number_of_rows() list[int][source]
title_displays_custom_title() list[bool][source]
title_displays_device_name() list[bool][source]
title_displays_settings_name() list[bool][source]
title_displays_shell_path() list[bool][source]
title_displays_window_size() list[bool][source]
class PyXA.apps.Terminal.XATerminalTab(properties)[source]

Bases: XAObject, XAClipboardCodable

A class for managing and interacting with tabs in Terminal.app.

New in version 0.0.1.

Attributes:

busy

Whether the tab is currently busy running a process.

contents

The currently visible contents of the tab.

current_settings

The set of settings which control the tab's behavior and appearance.

custom_title

The tab's custom title.

history

The contents of the entire scrolling buffer of the tab.

number_of_columns

The number of columns displayed in the tab.

number_of_rows

The number of rows displayed in the tab.

processes

The processes currently running in the tab.

selected

Whether the tab is currently selected.

title_displays_custom_title

Whether the tab's title contains a custom title.

tty

The tab's TTY device.

Methods:

get_clipboard_representation()

Gets a clipboard-codable representation of the tab.

property busy: bool

Whether the tab is currently busy running a process.

property contents: str

The currently visible contents of the tab.

property current_settings: XATerminalSettingsSet

The set of settings which control the tab’s behavior and appearance.

property custom_title: str

The tab’s custom title.

get_clipboard_representation() list[str][source]

Gets a clipboard-codable representation of the tab.

When the clipboard content is set to a Terminal tab, the tab’s custom title and its history are added to the clipboard.

Returns:

The tab’s custom title and history

Return type:

list[str]

New in version 0.0.8.

property history: str

The contents of the entire scrolling buffer of the tab.

property number_of_columns: int

The number of columns displayed in the tab.

property number_of_rows: int

The number of rows displayed in the tab.

property processes: list[str]

The processes currently running in the tab.

property selected: bool

Whether the tab is currently selected.

property title_displays_custom_title: bool

Whether the tab’s title contains a custom title.

property tty: str

The tab’s TTY device.

class PyXA.apps.Terminal.XATerminalTabList(properties: dict, filter: dict | None = None)[source]

Bases: XAList, XAClipboardCodable

A wrapper around lists of Terminal tabs that employs fast enumeration techniques.

All properties of tabs can be called as methods on the wrapped list, returning a list containing each tab’s value for the property.

New in version 0.0.7.

Methods:

busy()

by_busy(busy)

by_contents(contents)

by_current_settings(current_settings)

by_custom_title(custom_title)

by_history(history)

by_number_of_columns(number_of_columns)

by_number_of_rows(number_of_rows)

by_processes(processes)

by_selected(selected)

by_title_displays_custom_title(...)

by_tty(tty)

contents()

current_settings()

custom_title()

get_clipboard_representation()

Gets a clipboard-codable representation of each tab in the list.

history()

number_of_columns()

number_of_rows()

processes()

selected()

title_displays_custom_title()

tty()

busy() list[bool][source]
by_busy(busy: bool) XATerminalTab | None[source]
by_contents(contents: str) XATerminalTab | None[source]
by_current_settings(current_settings: XATerminalSettingsSet) XATerminalTab | None[source]
by_custom_title(custom_title: str) XATerminalTab | None[source]
by_history(history: str) XATerminalTab | None[source]
by_number_of_columns(number_of_columns: int) XATerminalTab | None[source]
by_number_of_rows(number_of_rows: int) XATerminalTab | None[source]
by_processes(processes: list[str]) XATerminalTab | None[source]
by_selected(selected: bool) XATerminalTab | None[source]
by_title_displays_custom_title(title_displays_custom_title: bool) XATerminalTab | None[source]
by_tty(tty: str) XATerminalTab | None[source]
contents() list[str][source]
current_settings() XATerminalSettingsSetList[source]
custom_title() list[str][source]
get_clipboard_representation() list[str][source]

Gets a clipboard-codable representation of each tab in the list.

When the clipboard content is set to a list of Terminal tabs, each tab’s custom title and history are added to the clipboard.

Returns:

The list of each tab’s custom title and history

Return type:

list[str]

New in version 0.0.8.

history() list[str][source]
number_of_columns() list[int][source]
number_of_rows() list[int][source]
processes() list[list[str]][source]
selected() list[bool][source]
title_displays_custom_title() list[bool][source]
tty() list[str][source]
class PyXA.apps.Terminal.XATerminalWindow(properties)[source]

Bases: XASBWindow, XASBPrintable, XAObject

A class for managing and interacting with windows in Terminal.app.

New in version 0.0.1.

Attributes:

frontmost

Whether the window is currently the frontmost Terminal window.

position

selected_tab

The Terminal tab currently displayed in the window.

Methods:

tabs([filter])

Returns a list of tabs, as PyXA-wrapped objects, matching the given filter.

property frontmost: bool

Whether the window is currently the frontmost Terminal window.

property position: tuple[int, int]
property selected_tab: XATerminalTab

The Terminal tab currently displayed in the window.

tabs(filter: dict | None = None) XATerminalTabList | None[source]

Returns a list of tabs, as PyXA-wrapped objects, matching the given filter.

Parameters:

filter (Union[dict, None]) – A dictionary specifying property-value pairs that all returned tabs will have, or None

Returns:

The list of tabs

Return type:

XATerminalTabList

New in version 0.0.7.