Cannot post notifications from osascript -l JavaScript

Originator:peter
Number:rdar://18923125 Date Originated:2014-11-10
Status:Closed Resolved:
Product:OS X Product Version:Yosemite
Classification: Reproducible:Always
 
In osascript -l JavaScript scripts,

$.NSUserNotificationCenter('defaultUserNotificationCenter')

returns NULL.  Presumably osascript isn't enough of an application to get a defaultUserNotificationCenter.  Regardless, this is a nuisance for people trying to write JavaScript for Automation scripts.

Comments

Need CFBundleIdentifier

Going further with my previous comment, the reason defaultUserNotificationCenter returns NULL in this situation is because when you compile with osascript or osacompile, your applet does not have a CFBundleIdentifier. An identifier is a requirement to access the defaultNotificationCenter.

Submitted a new report

I bumped into this today too, I went ahead and submitted another report http://openradar.appspot.com/radar?id=6099402275946496

I really think they should fix this. As I mention in that report, accessing the defaultNotfiicationCenter when compiling scripts with Script Editor app works as expected. I think osacompile should function the same way has Script Editor.

I haven't been able to identify what exactly is different between the two compilation processes (if anything) that produces the different outcome.

Use the "display notification" scripting addition

Apple responds that they have no plans to fix this, but you can post notifications using the "display notification" scripting addition.

app = Application.currentApplication() app.includeStandardAdditions = true app. displayNotification('Hello world')

Note that Application.currentApplication() complains osascript does not have a scripting dictionary, but we expect that sort of excess logging and error reports from Apple by now.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!