macos: use value-style AppleScript surface configuration records

Add a `surface configuration` record type to the scripting dictionary,
implement `new surface configuration` (with optional copy-from), and allow
`new window` to accept `with configuration`.
This commit is contained in:
Mitchell Hashimoto
2026-03-06 11:17:08 -08:00
parent 959c2f51ac
commit a3adeb0166
4 changed files with 232 additions and 1 deletions

View File

@@ -126,11 +126,28 @@ extension NSApplication {
return NSNumber(value: terminal.perform(action: action))
}
/// Handler for creating a reusable AppleScript surface configuration object.
@objc(handleNewSurfaceConfigurationScriptCommand:)
func handleNewSurfaceConfigurationScriptCommand(_ command: NSScriptCommand) -> Any? {
do {
let configuration = try Ghostty.SurfaceConfiguration(
scriptRecord: command.evaluatedArguments?["configuration"] as? NSDictionary
)
return configuration.dictionaryRepresentation
} catch {
command.scriptErrorNumber = errAECoercionFail
command.scriptErrorString = error.localizedDescription
return nil
}
}
/// Handler for the `new window` AppleScript command.
///
/// Required selector name from the command in `sdef`:
/// `handleNewWindowScriptCommand:`.
///
/// Accepts an optional reusable surface configuration object.
///
/// Returns the newly created scripting window object.
@objc(handleNewWindowScriptCommand:)
func handleNewWindowScriptCommand(_ command: NSScriptCommand) -> Any? {
@@ -140,7 +157,21 @@ extension NSApplication {
return nil
}
let controller = TerminalController.newWindow(appDelegate.ghostty)
let baseConfig: Ghostty.SurfaceConfiguration
do {
baseConfig = try Ghostty.SurfaceConfiguration(
scriptRecord: command.evaluatedArguments?["configuration"] as? NSDictionary
)
} catch {
command.scriptErrorNumber = errAECoercionFail
command.scriptErrorString = error.localizedDescription
return nil
}
let controller = TerminalController.newWindow(
appDelegate.ghostty,
withBaseConfig: baseConfig
)
let createdWindowID = ScriptWindow.stableID(primaryController: controller)
if let scriptWindow = scriptWindows.first(where: { $0.stableID == createdWindowID }) {