mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-05-28 15:55:20 +00:00
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:
@@ -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 }
|
||||
|
||||
Reference in New Issue
Block a user