mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-08 21:04:32 +00:00
macos: add focus and close AppleScript commands for terminals
Add two new AppleScript commands to the scripting dictionary: - `focus terminal <terminal>` — focuses the given terminal and brings its window to the front. - `close terminal <terminal>` — closes the given terminal without a confirmation prompt. Each command is implemented as an NSScriptCommand subclass following the same pattern as the existing split command.
This commit is contained in:
33
macos/Sources/Features/AppleScript/ScriptFocusCommand.swift
Normal file
33
macos/Sources/Features/AppleScript/ScriptFocusCommand.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
import AppKit
|
||||
|
||||
/// Handler for the `focus` AppleScript command defined in `Ghostty.sdef`.
|
||||
///
|
||||
/// Cocoa scripting instantiates this class because the command's `<cocoa>` element
|
||||
/// specifies `class="GhosttyScriptFocusCommand"`. The runtime calls
|
||||
/// `performDefaultImplementation()` to execute the command.
|
||||
@MainActor
|
||||
@objc(GhosttyScriptFocusCommand)
|
||||
final class ScriptFocusCommand: NSScriptCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let terminal = evaluatedArguments?["terminal"] as? ScriptTerminal else {
|
||||
scriptErrorNumber = errAEParamMissed
|
||||
scriptErrorString = "Missing terminal target."
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let surfaceView = terminal.surfaceView else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Terminal surface is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let controller = surfaceView.window?.windowController as? BaseTerminalController else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Terminal is not in a window."
|
||||
return nil
|
||||
}
|
||||
|
||||
controller.focusSurface(surfaceView)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user