Utilities for interacting with NSAppleScript
in Swift.
fourCharCode(_:)
- creates aFourCharCode
from a 4-character ASCII string.NSAppleScript.rawHandler(named:)
- returns a closure that invokes a handler in the script withNSAppleEventDescriptor
argument and return value.- Typed handlers:
NSAppleEventDescriptorConvertible
- a protocol for types that can be converted two-way into and fromNSAppleEventDescriptor
NSAppleScript.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))