Using Mathematica 11.0.1 on Windows 10 or Linux (openSuse) this does work:
abortAll[] := FrontEndTokenExecute["EvaluatorAbort"];
Do[Print[i]; If[i > 2, abortAll[]]; Pause[.2]; , {i, 10}]
Print["*"]; abortAll[]; Print["**"];
works on Linux.
On Windows it depends on the setting of CurrentValue[$FrontEnd, PrintAction]
:
For the default CurrentValue[$FrontEnd, PrintAction] = "PrintToNotebook";
the second print cell with "**" shows up. However, for CurrentValue[$FrontEnd, PrintAction] = "PrintToConsole";
(as I have it normally, even though I do not understand why it is called "PrintToConsole", since it prints to a Messages window) there is only one Print executed.
On Linux it just works consistently.
On macOS 10.12 using Mathematica 11.0.1 always both Print's are evaluated.
If anybody cares to use this on the cloud, then:
If[$Notebooks&&!$CloudEvaluation,CurrentValue[$FrontEnd, PrintAction] = "PrintToConsole"];
abortAll[] := If[$Notebooks&&!$CloudEvaluation, FrontEndTokenExecute["EvaluatorAbort"],Abort[]];
Print["*"]; abortAll[]; Print["**"];
which leaves me puzzled why $Notebooks
is True
when $CloudEvaluation
is True
.
Interrupt
and select "Abort Command Being Evaluated" in the dialog. $\endgroup$