mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-06-03 10:24:51 +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:
@@ -13,6 +13,9 @@
|
||||
<responds-to command="perform action">
|
||||
<cocoa method="handlePerformActionScriptCommand:"/>
|
||||
</responds-to>
|
||||
<responds-to command="new window">
|
||||
<cocoa method="handleNewWindowScriptCommand:"/>
|
||||
</responds-to>
|
||||
<responds-to command="quit">
|
||||
<cocoa method="handleQuitScriptCommand:"/>
|
||||
</responds-to>
|
||||
@@ -71,6 +74,10 @@
|
||||
<result type="boolean" description="True when the action was performed."/>
|
||||
</command>
|
||||
|
||||
<command name="new window" code="GhstNWin" description="Create a new Ghostty window.">
|
||||
<result type="window" description="The newly created window."/>
|
||||
</command>
|
||||
|
||||
<enumeration name="split direction" code="GSpD" description="Direction for a new split.">
|
||||
<enumerator name="right" code="GSrt" description="Split to the right."/>
|
||||
<enumerator name="left" code="GSlf" description="Split to the left."/>
|
||||
|
||||
@@ -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