Reputation: 91
Attempting to run an apple script In Xcode Using the swift language, when i Build my project and run it i receive an error that i searched google for with no help Here is what i have Running in my IBaction Submit button
let myAppleScript = "/calc.scpt"
var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript) {
if let outputString =
scriptObject.executeAndReturnError(&error).stringValue {
print(outputString)
} else if (error != nil) {
print("error: ", error!)
}
}
this error message is displayed in Debug Area >
error: {
NSAppleScriptErrorBriefMessage = "A \U201c/\U201d can\U2019t go here.";
NSAppleScriptErrorMessage = "A \U201c/\U201d can\U2019t go here.";
NSAppleScriptErrorNumber = "-2740";
NSAppleScriptErrorRange = "NSRange: {0, 1}";
}
any suggestions?
Upvotes: 2
Views: 272
Reputation: 539775
let myAppleScript = "/calc.scpt"
if let scriptObject = NSAppleScript(source: myAppleScript) { ... }
creates a script object with the given source code, i.e. /calc.scpt
is interpreted as AppleScript commands (and the error
message is about the initial slash character).
To create a script object from an AppleScript source file, use init?(contentsOf:error:)
:
let scriptURL: URL = // ... URL for "calc.scpt" file
var error: NSDictionary?
if let scriptObject = NSAppleScript(contentsOf: scriptURL, error: &error) {
// ...
}
Upvotes: 1