macos: expose name (title) on window, tab, and terminal via AppleScript

Add a `name` property (code `pnam`, cocoa key `title`) to the window, tab,
and terminal classes in the scripting definition. This follows the standard
Cocoa scripting convention where `name`/`pnam` maps to the `title` KVC key,
matching what Apple does in CocoaStandard.sdef for NSWindow.

Also fixes the pre-existing terminal `title` property which used a custom
four-char code (`Gttl`) that AppleScript could not resolve directly — only
via `properties of terminal`. All three classes now use the standard `pnam`
code so `name of window 1`, `name of tab 1 of window 1`, and
`name of terminal 1` all work correctly.
This commit is contained in:
Mitchell Hashimoto
2026-03-06 08:11:56 -08:00
parent e514035519
commit 122d0ecdfd
3 changed files with 25 additions and 1 deletions

View File

@@ -29,6 +29,9 @@
<class name="window" code="Gwnd" plural="windows" description="A Ghostty window containing one or more tabs.">
<cocoa class="GhosttyScriptWindow"/>
<property name="id" code="ID " type="text" access="r" description="Stable ID for this window."/>
<property name="name" code="pnam" type="text" access="r" description="The title of the window.">
<cocoa key="title"/>
</property>
<property name="selected tab" code="GWsT" type="tab" access="r" description="The selected tab in this window.">
<cocoa key="selectedTab"/>
</property>
@@ -43,6 +46,9 @@
<class name="tab" code="Gtab" plural="tabs" description="A tab within a Ghostty window.">
<cocoa class="GhosttyScriptTab"/>
<property name="id" code="ID " type="text" access="r" description="Stable ID for this tab."/>
<property name="name" code="pnam" type="text" access="r" description="The title of the tab.">
<cocoa key="title"/>
</property>
<property name="index" code="pidx" type="integer" access="r" description="1-based index of this tab in its window."/>
<property name="selected" code="GTsl" type="boolean" access="r" description="Whether this tab is selected in its window."/>
<element type="terminal" access="r">
@@ -53,7 +59,9 @@
<class name="terminal" code="Gtrm" plural="terminals" description="An individual terminal surface.">
<cocoa class="GhosttyScriptTerminal"/>
<property name="id" code="ID " type="text" access="r" description="Stable ID for this terminal surface."/>
<property name="title" code="Gttl" type="text" access="r" description="Current terminal title."/>
<property name="name" code="pnam" type="text" access="r" description="Current terminal title.">
<cocoa key="title"/>
</property>
<property name="working directory" code="Gwdr" type="text" access="r" description="Current working directory for the terminal process."/>
</class>

View File

@@ -37,6 +37,14 @@ final class ScriptTab: NSObject {
stableID
}
/// Exposed as the AppleScript `title` property.
///
/// Returns the title of the tab's window.
@objc(title)
var title: String {
controller?.window?.title ?? ""
}
/// Exposed as the AppleScript `index` property.
///
/// Cocoa scripting expects this to be 1-based for user-facing collections.

View File

@@ -42,6 +42,14 @@ final class ScriptWindow: NSObject {
stableID
}
/// Exposed as the AppleScript `title` property.
///
/// Returns the title of the window (from the selected/primary controller's NSWindow).
@objc(title)
var title: String {
selectedController?.window?.title ?? ""
}
/// Exposed as the AppleScript `tabs` element.
///
/// Cocoa asks for this collection when a script evaluates `tabs of window ...`