I have encountered this problem in my LaTeX editor project (which is not free software): Can a Mathematica notebook be programmed to work as a LaTeX editor?
The notebook of a LaTeX document typically includes hundreds of cells that can generate LaTeX source code. The evaluation of one of these cells is supposed to trigger a compilation by pdflatex to generate a PDF file. On the other hand, we would also like to be able to evaluate a selection of many cells of this type (or the entire notebook) while triggering only one pdflatex compilation (from LaTeX source concatenated from all cells of the evaluated selection).
In short, we want to trigger a pdflatex compilation just after evaluating the selection, that is, when the evaluation queue is empty.
To determine when a selection completes its evaluation, I used $ Pre to stop a timer at the beginning of any cell evaluation and to reset and start the timer at the end of the cell evaluation. A scheduled task is configured to read the timer, for example every 0.1 s. If the timer has a value significantly greater than the expected delay between the end of one evaluation in the queue and the beginning of the next, we know that the selection must be made. have completed the evaluation and the front-end system is now waiting for the user's input.
I suppose that there is a much simpler solution to this problem because Mathematica displays the message "Being processed …" in the title of the notebook window during the evaluation of a selection.