macos: add pid and tty properties to AppleScript terminal class

Expose the foreground process PID and TTY device path as read-only properties on the AppleScript terminal class and App Intents TerminalEntity. This enables reliable process-to-terminal mapping for automation tools when multiple terminals share the same CWD.

Closes #11592
Closes #10756

Session: 019d341c-a165-7843-a2f7-2f426114cf17
This commit is contained in:
Christo Wilken
2026-03-28 12:55:01 +01:00
parent dcc39dcd40
commit 9a9002202b
7 changed files with 63 additions and 2 deletions

View File

@@ -11,6 +11,8 @@ import AppKit
/// - `property id` -> `@objc(id)` getter below.
/// - `property title` -> `@objc(title)` getter below.
/// - `property working directory` -> `@objc(workingDirectory)` getter below.
/// - `property pid` -> `@objc(pid)` getter below.
/// - `property tty` -> `@objc(tty)` getter below.
///
/// We keep only a weak reference to the underlying `SurfaceView` so this
/// wrapper never extends the terminal's lifetime.
@@ -53,6 +55,20 @@ final class ScriptTerminal: NSObject {
return surfaceView?.pwd ?? ""
}
/// Exposed as the AppleScript `pid` property.
@objc(pid)
var pid: Int {
guard NSApp.isAppleScriptEnabled else { return 0 }
return surfaceView?.surfaceModel?.foregroundPID ?? 0
}
/// Exposed as the AppleScript `tty` property.
@objc(tty)
var tty: String {
guard NSApp.isAppleScriptEnabled else { return "" }
return surfaceView?.surfaceModel?.ttyName ?? ""
}
/// Used by command handling (`perform action ... on <terminal>`).
func perform(action: String) -> Bool {
guard NSApp.isAppleScriptEnabled else { return false }