10
$\begingroup$

Is it possible to use the option EvaluationCompletionAction to notify me (e.g. with a Beep[]) when an evaluation that took longer than, for example, 30s is finished?

One of the default settings for EvaluationCompletionAction is "ShowTiming" which indicates that the FrontEnd is in some way aware of the duration of evaluations.

Ideally, I would want something like this:

SetOptions[
  $FrontEnd,
  EvaluationCompletionAction -> Which[duration > 30, Beep[]]
]

Is it possible to do this? And could anyone point me in a direction how to accomplish this?

$\endgroup$
6
$\begingroup$

It doesn't seem to be possible with EvaluationCompletionAction but you can wrap input with custom function using $PreRead and friends:

$Pre = Function[expr, 
   Module[{start, result}, 
     start = AbsoluteTime[];
     result = expr;
     If[AbsoluteTime[] - start > 2, Speak @ "wow, it took at least 2 seconds"];
     result
  ],
  HoldAll
]

I'm using Speak instead of Beep because I can't make the latter work on my machine :P

So now, evaluating

Pause[3]

should Print a message.

$\endgroup$
4
  • $\begingroup$ Different approach but it works. Haven't met the $PreRead family before... $\endgroup$ – Aart Goossens Nov 26 '15 at 9:25
  • $\begingroup$ @AartGoossens yep, they are quite useful sometimes, you can search around for related answers. I'm glad it helps, good luck. :) $\endgroup$ – Kuba Nov 26 '15 at 9:27
  • 2
    $\begingroup$ @AartGoossens Make it Speak[ ] something... it is much funnier! You can even randomly choose from a list of jokes... $\endgroup$ – P. Fonseca Nov 26 '15 at 16:45
  • $\begingroup$ @P.Fonseca :-)) Best idea ever, done :) $\endgroup$ – Kuba Nov 26 '15 at 16:48

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.