From 122d0ecdfd9947d0c8c34953d0babc39502556e5 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 6 Mar 2026 08:11:56 -0800 Subject: [PATCH] macos: expose name (title) on window, tab, and terminal via AppleScript MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- macos/Ghostty.sdef | 10 +++++++++- macos/Sources/Features/AppleScript/ScriptTab.swift | 8 ++++++++ macos/Sources/Features/AppleScript/ScriptWindow.swift | 8 ++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/macos/Ghostty.sdef b/macos/Ghostty.sdef index c3d58e043..d0c8cb9a2 100644 --- a/macos/Ghostty.sdef +++ b/macos/Ghostty.sdef @@ -29,6 +29,9 @@ + + + @@ -43,6 +46,9 @@ + + + @@ -53,7 +59,9 @@ - + + + diff --git a/macos/Sources/Features/AppleScript/ScriptTab.swift b/macos/Sources/Features/AppleScript/ScriptTab.swift index 69ce56779..aa643db5a 100644 --- a/macos/Sources/Features/AppleScript/ScriptTab.swift +++ b/macos/Sources/Features/AppleScript/ScriptTab.swift @@ -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. diff --git a/macos/Sources/Features/AppleScript/ScriptWindow.swift b/macos/Sources/Features/AppleScript/ScriptWindow.swift index 61c0f7788..f6cfeaa77 100644 --- a/macos/Sources/Features/AppleScript/ScriptWindow.swift +++ b/macos/Sources/Features/AppleScript/ScriptWindow.swift @@ -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 ...`