In Yosemite it now is possible to use JavaScript for automation as well as Applescript. I am having trouble with certain StandardAdditions commands. E.g. from the Contacts application I can use displayAlert, but not displayNotification. Both are in the StandardsAdditions dictionary. When running these commands through the ScriptEditor I don't get these issues.
For the commands that fail I get at runtime: Error -10004: A privilege violation occurred.
Example code in JavaScript:
ScriptEditor = Application("Script Editor");
ScriptEditor.includeStandardAdditions = true;
app = Application("Contacts"); // or e.g. "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 the equivalent code in AppleScript I do not get privilege violation errors:
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 (!)
What I notice in that case though is that the Contacts alert shows up with the Contacts icon (and Contacts app is activated), but the Contacts notification shows up with the Script Editor icon (and the Contacts app is not activated).
Using Yosemite 10.10. Is this a bug or am I missing something?
.currentApplication()
(ie Script Editor) with anything else. I assume this is intentional (can't cause another app to "say" stuff?) but wish it were documented with rationale. – EmdenApplication.currentApplication()
instead of another application to rundisplayNotification()
. – Signesignet