$Post, whose value, if set, is applied to every output expression.
In particular, if one sets
$Post = (f; #)&
then at the completion of any cell evaluation (e.g., one started by doing
Shift+Enter on an
Input cell), the expression
f will be evaluated.
Is there a simple implementation of an analogous functionality for selection evaluations ?
The difference is that a selection evaluation may involve a queue of many cell evaluations, but I only want
f to be evaluated once, immediately
after the last cell in the queue has finished evaluating. I.e., when the evaluation queue becomes empty.
I know of one way to do this (and it is works perfectly well for my usage) but my solution seems overly tricky. (A nice thing about writing the
A for this Q is that I'll never again have to spend excessive time figuring out the code before making minor edits.) Moreover, my code
$Pre. This is messy, because I'm also using
$Pre elsewhere in the same software, so I already need to compose several different values for
My suspicion is that there exists a built-in (hidden) function for detecting whether the evaluation queue is empty or not, because
it is sort of obvious.... If the notebook window title says "Running..." then the evaluation queue is not empty. A function, let's call it
RunningQ, that would would tell me if the notebook was running would suffice because a ScheduledTask could be used to
f as soon as
RunningQ is detected as having changed from
Perhaps there is something in WSTP that does what I want? I have no experience in that area, so perhaps this is a completely trivial question for someone else who does (which is why I've tagged it).
An alternative presentation of the same question
Suppose I want to be notified by a bell when a long evaluation in my notebook finishes running. Suppose also that I am not aware of this answer by "rm -rf" for that problem, so instead I use the following code:
$Post = (EmitSound[SoundNote["G"]]; #)&
Now, every time I do Shift+Enter on a cell, I get a bell notification at the end of the cell evaluation. I can put up with this because I sometimes find it useful if a cell evaluation takes more than a minute or so.
But then I discover why this
$Post idea is not OK:
$Post is applied post cell evaluation not post selection evaluation. If, for example,
I select 10 consecutive cells that each evaluate
Pause[0.1], then when I evaluate this selection I get 10 bells rather than just one bell at the end of the selection evaluation. Since I often use a mouse-drag to select 100s of cells to be evaluated as one selection, this
$Post idea is of no use to me.
How can I get just one bell to ring at the end of a selection evaluation?
For my application, it is important that no additional user-interaction be required, such as clicking a button, doing
Shift+Enter on something in another notebook, selecting a menu item, etc.
BTW, after you try the above code, normal evaluation (without a bell) can be restored by setting
$Post = ..