macos: Add AppleScript commands for window and tab control

Add scripting dictionary commands for activating windows, selecting tabs,
closing tabs, and closing windows.

Implement the corresponding Cocoa AppleScript command handlers and expose
minimal ScriptWindow/ScriptTab helpers needed to resolve live targets.

Verified by building Ghostty and running osascript commands against the
absolute Debug app path to exercise all four new commands.
This commit is contained in:
Mitchell Hashimoto
2026-03-06 14:31:03 -08:00
parent d271c8ccaa
commit 28b4e2495d
5 changed files with 149 additions and 0 deletions

View File

@@ -116,6 +116,11 @@ final class ScriptWindow: NSObject {
selectedController?.window ?? controllers.first?.window
}
/// Best-effort controller to use for window-scoped AppleScript commands.
var preferredController: BaseTerminalController? {
selectedController ?? controllers.first
}
/// Resolves a previously generated tab ID back to a live controller.
private func controller(tabID: String) -> BaseTerminalController? {
controllers.first(where: { ScriptTab.stableID(controller: $0) == tabID })