6

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?

  • 1
    Pro tip: You can use emoji in AppleScript notifications. – Nathan Arthur Mar 21 '17 at 21:51
8

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
  • Thank you, terminal-notifier is perfect. Btw, it's available via homebrew. – qqilihq Oct 1 '14 at 8:16
0

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!"'
  • No matter what I specify as application name, it always shows with the Script Editor icon and application name. – qqilihq Jul 31 '17 at 7:05
  • Oh. Ok... To be honest, I only tried it from a terminal window. My bad! (unless there's a bug... after all, why would it work differently from the script editor... hmmm) – Erk Jul 31 '17 at 11:57
  • I think I just figured this one out. When I run my script as "me" it shows the apple script icon as well... but when I "sudo" the script, it shows the icon of the program I "told". I.e. you need to call the command as "root" to make it "order" other applications to do stuff... makes some sense... I updated the code to reflect this. – Erk Dec 1 '17 at 19:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .