mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-20 22:35:20 +00:00
macos: add AppleScript new window command
Add a `new window` command to the scripting dictionary and wire it to `NSApplication` so AppleScript can create Ghostty windows. The command returns a scripting `window` object for the created window, with a fallback to a direct wrapper when AppKit window ordering has not yet refreshed in the current run loop.
This commit is contained in:
@@ -125,6 +125,32 @@ extension NSApplication {
|
||||
|
||||
return NSNumber(value: terminal.perform(action: action))
|
||||
}
|
||||
|
||||
/// Handler for the `new window` AppleScript command.
|
||||
///
|
||||
/// Required selector name from the command in `sdef`:
|
||||
/// `handleNewWindowScriptCommand:`.
|
||||
///
|
||||
/// Returns the newly created scripting window object.
|
||||
@objc(handleNewWindowScriptCommand:)
|
||||
func handleNewWindowScriptCommand(_ command: NSScriptCommand) -> Any? {
|
||||
guard let appDelegate = delegate as? AppDelegate else {
|
||||
command.scriptErrorNumber = errAEEventFailed
|
||||
command.scriptErrorString = "Ghostty app delegate is unavailable."
|
||||
return nil
|
||||
}
|
||||
|
||||
let controller = TerminalController.newWindow(appDelegate.ghostty)
|
||||
let createdWindowID = ScriptWindow.stableID(primaryController: controller)
|
||||
|
||||
if let scriptWindow = scriptWindows.first(where: { $0.stableID == createdWindowID }) {
|
||||
return scriptWindow
|
||||
}
|
||||
|
||||
// Fall back to wrapping the created controller if AppKit window ordering
|
||||
// has not refreshed yet in the current run loop.
|
||||
return ScriptWindow(primaryController: controller)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private Helpers
|
||||
|
||||
Reference in New Issue
Block a user