10
$\begingroup$

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

$\endgroup$
14
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ I don't know. The linked thread says 10.9. It works for me on 10.12. Output is as expected. $\endgroup$ – Szabolcs Oct 30 '17 at 14:08
  • $\begingroup$ 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. $\endgroup$ – Szabolcs Oct 30 '17 at 14:23
  • 3
    $\begingroup$ 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. $\endgroup$ – José Antonio Díaz Navas Oct 30 '17 at 14:27
  • $\begingroup$ (+1) It's too bad osascript doesn't allow you to change the icon. $\endgroup$ – Chip Hurst Oct 30 '17 at 18:04
  • 2
    $\begingroup$ @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. $\endgroup$ – Casimir Oct 31 '17 at 20:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.