mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 11:35:48 +00:00
macos: add AppleScript commands for text input, key, and mouse events
Add five new AppleScript commands to Ghostty.sdef mirroring the existing App Intents for terminal input: - `input text`: send text to a terminal as if pasted - `send key`: simulate a keyboard event with optional action and modifiers - `send mouse button`: send a mouse button press/release event - `send mouse position`: send a mouse cursor position event - `send mouse scroll`: send a scroll event with precision and momentum A shared `input action` enumeration (press/release) is used by both key and mouse button commands. Modifier keys are passed as a comma-separated string parameter (shift, control, option, command).
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import AppKit
|
||||
|
||||
/// Handler for the `input text` AppleScript command defined in `Ghostty.sdef`.
|
||||
///
|
||||
/// Cocoa scripting instantiates this class because the command's `<cocoa>` element
|
||||
/// specifies `class="GhosttyScriptInputTextCommand"`. The runtime calls
|
||||
/// `performDefaultImplementation()` to execute the command.
|
||||
@MainActor
|
||||
@objc(GhosttyScriptInputTextCommand)
|
||||
final class ScriptInputTextCommand: NSScriptCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let text = directParameter as? String else {
|
||||
scriptErrorNumber = errAEParamMissed
|
||||
scriptErrorString = "Missing text to input."
|
||||
return nil
|
||||
}
|
||||
|
||||
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 surface = surfaceView.surfaceModel else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Terminal surface model is not available."
|
||||
return nil
|
||||
}
|
||||
|
||||
surface.sendText(text)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user