Cannot execute AppleScript from app.

I am trying to run an AppleScript from my app which is sandboxed. I have got the user's consent(NSOpenPanel) to root directory so the app has permission to ready anything. I am not able to run any script, even a simple one like echo 'hellow world'. I tried to run it on the main thread with dispath_async(or performselectoronmainthread) but without success. The script part is as below :


NSString *zipScript = [NSString stringWithFormat:@"do shell script \"echo 'hello world'\""];

NSAppleScript *script = [[NSAppleScript alloc] initWithSource:zipScript];

NSDictionary *error2;

[script executeAndReturnError:&error2];

if(error2)

{

return false;

}


Full description of error2 is (i have removed the app's name) :

{

NSAppleScriptErrorAppName = "XXXXXXXX";

NSAppleScriptErrorBriefMessage = "The command terminated due to receipt of a signal.";

NSAppleScriptErrorMessage = "The command terminated due to receipt of a signal.";

NSAppleScriptErrorNumber = 1011;

NSAppleScriptErrorRange = "NSRange: {0, 170}";

}


Is there any reason/solution for this error?


Thanks in advance.

Replies

You’re unlikely to make any headway with

NSAppleScript
inside a sandboxed app (AppleScript is intimately tied to Apple events and Apple events are severely restricted by the sandbox). You should look at
NSUserScriptTask
. This allows your app to execute user selected scripts such that those script run outside of the sandbox.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"