Applescript from Mac App says "Expected end of line but found \U201c\"\U201d."

Posted by Rasmus Styrk on Stack Overflow See other posts from Stack Overflow or by Rasmus Styrk
Published on 2012-06-13T15:51:12Z Indexed on 2012/07/05 21:16 UTC
Read the original article Hit count: 336

I am trying to perform a copy/paste for my to the the last active app, here's my code:

NSString *appleScriptSource = [NSString stringWithFormat:@"\ntell application \"%@\" to activate\ntell application \"System Events\" to tell process \"%@\"\nkeystroke \"v\" using command down\nend tell", [lastApp localizedName], [lastApp localizedName]];

NSDictionary *error;
NSAppleScript *aScript = [[NSAppleScript alloc] initWithSource:appleScriptSource];
NSAppleEventDescriptor *aDescriptor = [aScript executeAndReturnError:&error];

The problem is that on some computers it works just fine, but on others it fails. My error output from error that is returned by executeAndReturnError is:

2012-06-13 17:43:19.875 Mini Translator[1206:303] (null) (error: {
    NSAppleScriptErrorBriefMessage = "Expected end of line but found \U201c\"\U201d.";
    NSAppleScriptErrorMessage = "Expected end of line but found \U201c\"\U201d.";
    NSAppleScriptErrorNumber = "-2741";
    NSAppleScriptErrorRange = "NSRange: {95, 1}";
})

I can't seem to figure out what it means or why it happens.

We tried copying the generated apple-script code into the Apple Script editor, and here it works just fine.

My App is sandboxed - i have added the bundle identifiers for the key "com.apple.security.temporary-exception.apple-events" for the apps i want to support.

Any suggestions?

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about applescript