Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions macos/Ghostty.sdef
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<property name="frontmost" code="pisf" type="boolean" access="r" description="Is this the active application?">
<cocoa key="isActive"/>
</property>
<property name="front window" code="GFWn" type="window" access="r" description="The frontmost Ghostty window.">
<cocoa key="frontWindow"/>
</property>
<property name="version" code="vers" type="text" access="r" description="The version number of the application."/>
<responds-to command="perform action">
<cocoa method="handlePerformActionScriptCommand:"/>
Expand Down Expand Up @@ -66,6 +69,9 @@
</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."/>
<property name="focused terminal" code="GTfT" type="terminal" access="r" description="The currently focused terminal surface in this tab.">
<cocoa key="focusedTerminal"/>
</property>
<responds-to command="select tab">
<cocoa method="handleSelectTabCommand:"/>
</responds-to>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ extension NSApplication {
return result
}

/// Exposed as the AppleScript `front window` property.
///
/// `scriptWindows` is already ordered front-to-back, so the first item is
/// the frontmost logical Ghostty window.
@objc(frontWindow)
var frontWindow: ScriptWindow? {
guard isAppleScriptEnabled else { return nil }
return scriptWindows.first
}

/// Enables AppleScript unique-ID lookup for window references.
///
/// Required selector name pattern for element key `scriptWindows`:
Expand Down
14 changes: 14 additions & 0 deletions macos/Sources/Features/AppleScript/ScriptTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ final class ScriptTab: NSObject {
return window?.tabIsSelected(controller) ?? false
}

/// Exposed as the AppleScript `focused terminal` property.
///
/// Uses the currently focused surface for this tab.
@objc(focusedTerminal)
var focusedTerminal: ScriptTerminal? {
guard NSApp.isAppleScriptEnabled else { return nil }
guard let controller else { return nil }
guard let surface = controller.focusedSurface,
controller.surfaceTree.contains(surface)
else { return nil }

return ScriptTerminal(surfaceView: surface)
}

/// Best-effort native window containing this tab.
var parentWindow: NSWindow? {
guard NSApp.isAppleScriptEnabled else { return nil }
Expand Down
Loading