Utilities for interacting with NSAppleScript in Swift.
fourCharCode(_:)- creates aFourCharCodefrom a 4-character ASCII string.NSAppleScript.rawHandler(named:)- returns a closure that invokes a handler in the script withNSAppleEventDescriptorargument and return value.- Typed handlers:
NSAppleEventDescriptorConvertible- a protocol for types that can be converted two-way into and fromNSAppleEventDescriptorNSAppleScript.handler(named:argumentTypes:returnType:)(and itsVoid-return equivalent) - returns a closure that invokes a handler in the script with typed argument and return values.
let source = """
to cube(theNumber)
return theNumber * theNumber * theNumber
end cube
"""
let script = NSAppleScript(source: source)!
let cube: (Double) throws -> Double = script.handler(named: "cube") // argument types inferred
print(try cube(3))