Javascript for Automation (OSA) Yosemite: Privilege Error for Specific StandardAddition Commands

Yosemite can now use JavaScript for automation , as well as Applescript. I'm having problems with some StandardAdditions commands. For example. from the Contacts application, I can use displayAlert , but not displayNotification . Both are in the StandardsAdditions dictionary. When I execute these commands through ScriptEditor, I do not get these problems.

For commands that do not work, I get at runtime: Error -10004: Privilege violation occurred .

Sample JavaScript code:

ScriptEditor = Application("Script Editor"); ScriptEditor.includeStandardAdditions = true; app = Application("Contacts"); // or eg "Calendar", "System Events", "Finder" app.includeStandardAdditions = true; // -- testing: displayAlert() ScriptEditor.displayAlert("Hello world!"); app.displayAlert("Hello world!"); // success, no privilege error // -- testing: displayNotification() ScriptEditor.displayNotification("Hello world!"); //app.displayNotification("Hello world!"); // Error -10004: A privilege violation occurred. // --- testing: say() ScriptEditor.say("Hello world!"); //app.say("Hello world"); // Error -10004: A privilege violation occurred. // --- testing: beep() ScriptEditor.beep(1); //app.beep(1); // Error -10004: A privilege violation occurred. 

When using equivalent code in AppleScript, I don’t see errors when violating privileges:

 tell application "Script Editor" to display alert "from Script Editor" -- with Script Editor icon tell application "Contacts" to display alert "from contacts" -- with Contacts icon tell application "Script Editor" to display notification "from Script Editor" -- with Script Editor icon tell application "Contacts" to display notification "from contacts" -- with Script Editor icon (!) 

In this case, I noticed that the alert message is displayed with the Contacts icon (and the Contacts application), but the Contacts notification the Script Editor icon is displayed (and the Contacts application is not activated).

Using Yosemite 10.10. Is this a mistake or am I missing something?

+7
javascript applescript osx-yosemite javascript-automation
source share
1 answer

The reason is because AppleScript uses inheritance. You can tell any application to "display a notification", but the call ends up passing the hierarchy to the Script Editor (or the Script applet) that understands this message. JavaScript implementation does not support inheritance as far as I know. I'm not very good at JavaScript in the OSA world. :)

tl; dr: Contacts cannot actually do what you are trying to do, it just works in AppleScript because AppleScript is awesome. :)

If you look at the response log in the Script Editor, you will see that inheritance happens live.

+1
source share

All Articles