Getting errors when executing AppleScript from within Swift App

38 views Asked by At

I'm using the NSAppleScript to run some code from within a swift app. The code runs and launches the Photos app but then I get the following error and no photos are exported:

error: { NSAppleScriptErrorAppName = Photos; NSAppleScriptErrorBriefMessage = "Application isn\U2019t running."; NSAppleScriptErrorMessage = "Photos got an error: Application isn\U2019t running."; NSAppleScriptErrorNumber = "-600"; NSAppleScriptErrorRange = "NSRange: {115, 16}"; }

My code is below. I can't pinpoint what the issue is as the code executes fine in AppleScript itself.

let myAppleScript2 = "set destination to \"/Users/user1/Downloads/photos/\" as POSIX file\r\ntell application \"Photos\"\r\nexport (get every media item in favorites album) to destination ¬\r\nwith using originals\r\nquit\r\nend tell"

var error: NSDictionary?
if let scriptObject = NSAppleScript(source: myAppleScript2) {
    if let outputString = scriptObject.executeAndReturnError(&error).stringValue {
        print(outputString)   
    } else if (error != nil) {
        print("error: ", error!)
    }
}
0

There are 0 answers