Notification Center message via AppleScript/osascript -- specify an application name and icon

When sending a notification to OS X's Notification Center via AppleScript's osascript, such as in:

osascript -e 'display notification "Finished that long running task." with title "Finally!"'

The Notification Center shows "AppleScript Editor" as the notification's source:

NotificationCenter

Is there a possibility to specify a different source (as in application) and icon when sending a notification this way?


Solution 1:

I don't think it's possible with AppleScript but it is with terminal-notifier:

-sender ID         The bundle identifier of the application that should be
shown as the sender, including its icon.
-appIcon URL       The URL of a image to display instead of the application
icon (Mavericks+ only)

For example:

terminal-notifier -title title -message message -sender com.apple.TextEdit

Solution 2:

You should be able to do

osascript -e 'tell app "System Events" to display notification "Finished that long running task." with title "Finally!"'

You can change "System Events" to any other application name.

It seems you need to be root to make it show other icons than Apple Script. E.g. in a terminal window:

sudo osascript -e 'tell app "System Events" to display notification "Finished that long running task." with title "Finally!"'