Using NSAppleScript Fails in Cocoa App But Works When Running From Script Editor

It is relevant to my app to have a button in my app's Preferences window to launch the System Preferences app. The reason why doing this is relevant is because there is a setting in System Preferences that affects my app, however my app cannot provide a user interface that allows the user to change this preference. So they have to go to System preferences.


I activate the System Preferences app and set the current pane to pane "pane here". I can run this in the Script Editor and it works fine. But if I copy the script on my apps main bundle and do:


NSURL *appleScriptURL = [[NSBundle mainBundle]URLForResource:@"SriptHere" withExtension:@"scpt"];

NSAppleScript *appleScript = [[NSAppleScript alloc]initWithContentsOfURL:appleScriptURL error:&errorInfo];
    NSAppleEventDescriptor *descriptor = [appleScript executeAndReturnError:&errorInfo];


I get


NSAppleScriptErrorMessage = "System Preferences got an error: Application isn\U2019t running.";

NSAppleScriptErrorNumber = "-600";


Is this because of the app is sandboxed? And if so, is there a supported way to open a System Preference pane in a sandboxed environment..I know I can just launch System Prefs with NSWorkspace...but I'd like to set the right pane to make it nice on users. (EDIT: Yes...the script works if I turn App sandboxing off...so the sandbox is blocking it).

just took a look at the entitlement key reference...only way to do it is to configure a temporary exception. Kind of a bummer.

Seems your workaround w/o drilling down into a specific pane is it - iOS works the same, BTW.


(-600)
is an operating system error.

An operating system error is an error that occurs when AppleScript or an application requests services from the Mac OS. They are rare, and often there is nothing you can do about them in a script, other than report them.

I have the same proble,Have you solved it?

thanks

I ended up just launching the System prefs app with NSWorkspace.


I'm not sure, but it may have been possible to try to use NSWorkspace openURL: to open a .prefPane file, I haven't tried though.

Using NSAppleScript Fails in Cocoa App But Works When Running From Script Editor
 
 
Q