mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-14 19:45:49 +00:00
macos: Add AppleScript commands for window and tab control
Add scripting dictionary commands for activating windows, selecting tabs, closing tabs, and closing windows. Implement the corresponding Cocoa AppleScript command handlers and expose minimal ScriptWindow/ScriptTab helpers needed to resolve live targets. Verified by building Ghostty and running osascript commands against the absolute Debug app path to exercise all four new commands.
This commit is contained in:
@@ -31,3 +31,63 @@ final class ScriptCloseCommand: NSScriptCommand {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler for the `close tab` AppleScript command defined in `Ghostty.sdef`.
|
||||
@MainActor
|
||||
@objc(GhosttyScriptCloseTabCommand)
|
||||
final class ScriptCloseTabCommand: NSScriptCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let tab = evaluatedArguments?["tab"] as? ScriptTab else {
|
||||
scriptErrorNumber = errAEParamMissed
|
||||
scriptErrorString = "Missing tab target."
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let controller = tab.parentController else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Tab is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
if let terminalController = controller as? TerminalController {
|
||||
terminalController.closeTabImmediately(registerRedo: false)
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let targetWindow = tab.parentWindow else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Tab window is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
targetWindow.close()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
/// Handler for the `close window` AppleScript command defined in `Ghostty.sdef`.
|
||||
@MainActor
|
||||
@objc(GhosttyScriptCloseWindowCommand)
|
||||
final class ScriptCloseWindowCommand: NSScriptCommand {
|
||||
override func performDefaultImplementation() -> Any? {
|
||||
guard let window = evaluatedArguments?["window"] as? ScriptWindow else {
|
||||
scriptErrorNumber = errAEParamMissed
|
||||
scriptErrorString = "Missing window target."
|
||||
return nil
|
||||
}
|
||||
|
||||
if let terminalController = window.preferredController as? TerminalController {
|
||||
terminalController.closeWindowImmediately()
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let targetWindow = window.preferredParentWindow else {
|
||||
scriptErrorNumber = errAEEventFailed
|
||||
scriptErrorString = "Window is no longer available."
|
||||
return nil
|
||||
}
|
||||
|
||||
targetWindow.close()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user