10

Is Mathematica able to communicate with macOS's native Notification Center in order to notify me if an evaluation finishes in any of my open notebooks?

I'm looking for a solution similar to this one except it shouldn't rely on Growl.

enter image description here

Janosh
  • 1,281
  • 8
  • 30

1 Answers1

14

A quick Google search returned:

Based on this, we can use

notify[asc_] := 
 RunProcess[{"osascript", "-e", 
   StringTemplate["display notification \"`message`\" with title \"`title`\""][asc]}]

notify[<|"message" -> "I'm finished!", "title" -> "Mathematica"|>]

You can customize this further to your needs.

Szabolcs
  • 234,956
  • 30
  • 623
  • 1,263
  • I don't know. The linked thread says 10.9. It works for me on 10.12. Output is as expected. – Szabolcs Oct 30 '17 at 14:08
  • Changing Mathematica settings is not necessary because all this does is it runs an AppleScript (see the linked post!) As for showing notifications after every evaluation: see CellEpilog from the thread that you yourself linked. You might try to set this in the stylesheet. – Szabolcs Oct 30 '17 at 14:23
  • 3
    I run in macOS 10.13 notify[asc_] := RunProcess[{"osascript", "-e", StringTemplate[ "display notification \"message\" with title \"title`""][ asc]}, "StandardOutput"]

    notify[<|"message" -> "I'm finished!", "title" -> "Mathematica"|>]`, and it works in MMA 11.2. It gives me a notification.

    – José Antonio Díaz Navas Oct 30 '17 at 14:27
  • (+1) It's too bad osascript doesn't allow you to change the icon. – Greg Hurst Oct 30 '17 at 18:04
  • 2
    @Szabolcs Please excuse my stupidity. The notifications do in fact work perfectly. I had "Do Not Disturb" enabled yesterday and had completely forgotten about it. – Janosh Oct 31 '17 at 20:20