16
$\begingroup$

It seems there are a lot of related topics but I haven't found an answer.

I want to automatically quit Mathematica after some procedures are done but dialog window appears:

1 + 1;
NotebookSave[EvaluationNotebook[]];
FrontEndExecute[FrontEndToken["FrontEndQuit"]]

enter image description here

One can put this inside Button

Button["close",
        1 + 1; NotebookSave[EvaluationNotebook[]];
        FrontEndExecute[FrontEndToken["FrontEndQuit"]]
      ]

what will work but I need it works as a part of procedure because the notebook is called automatically and no one is going to click OK.

This Q&A is almost a duplicate of undisputed FrontEndTokenExecute but there was the work around.

I appreciate a work around but also the general question, how to stop or automatically agree with Dialogs is what I'm interested in.

Maybe it's relevant: Win XP/Win 7 Mathematica V9.0.0.1

$\endgroup$
4
  • $\begingroup$ @Anon but when to close? :) It is called via WindowsTaskManager but I can switch to cmd if you show me how to catch some mark from MMA that will tell cdm to close it. $\endgroup$
    – Kuba
    Aug 23, 2013 at 11:21
  • $\begingroup$ By the way, isn't it strange that it offers to put the result to the MessageWindow since I'm closing MMA?:) $\endgroup$
    – Kuba
    Aug 23, 2013 at 11:34
  • 1
    $\begingroup$ Hah, I deleted my comment in like two seconds didn't think you'd see it... I realized it might not be viable for you. But what I meant was to save your notebook content into an .m file and execute it via command line. I didn't think there was reason to open a notebook in the first place if noone was there to see it. $\endgroup$
    – C. E.
    Aug 23, 2013 at 14:29
  • 7
    $\begingroup$ When I want to automatically close Mathematica, I do ListPlot3D[bigdata] and try to rotate the view :D :D $\endgroup$
    – rm -rf
    Aug 23, 2013 at 14:44

2 Answers 2

18
$\begingroup$

There's a separate FE token that can do this.

FrontEndTokenExecute["FrontEndQuitNonInteractive"]
$\endgroup$
5
  • 1
    $\begingroup$ Ahh, it's also on complete list there, thank you. Do you maybe know the answer for general question, about preventing Dialogs? The answer that we can't do anything is also information :) $\endgroup$
    – Kuba
    Aug 23, 2013 at 18:39
  • 2
    $\begingroup$ @Kuba, if you run the front end with the -server command-line option, then it will not prompt dialog boxes. But it will also not be usable by the user. This is, for example, how the kernel command UsingFrontEnd launches the kernel. Since you don't provide very much context for your question, it's not clear to me whether this is a useful answer to your question. $\endgroup$
    – John Fultz
    Aug 26, 2013 at 20:35
  • $\begingroup$ I was thinking about something like Check but detecting dialogs. Also with functionality to automatically agree or not with them. I do know if it is possible, just asking. $\endgroup$
    – Kuba
    Aug 28, 2013 at 10:03
  • 2
    $\begingroup$ @Kuba it's not possible to do anything like what you're asking for globally for arbitrary Mathematica commands. If you're sticking to fully documented Mathematica functions, you shouldn't ever see interactive prompts unless that's the purpose of the function (e.g., Input). But many of the FE tokens were implemented only for the purpose of user interaction through the menu system, and do not represent the gold standard of end-to-end design that we generally apply to fully documented functions. $\endgroup$
    – John Fultz
    Aug 28, 2013 at 16:29
  • $\begingroup$ Thank you, I think it exhausts the topic. :) $\endgroup$
    – Kuba
    Aug 28, 2013 at 18:08
9
$\begingroup$

As a workaround, try this:

1 + 1;
NotebookSave[EvaluationNotebook[]];
RunScheduledTask[FrontEndExecute[FrontEndToken["FrontEndQuit"]]];

This will only work if the kernel evaluations have actually finished, you can't use it half-way through a calculation.

$\endgroup$
3
  • $\begingroup$ Thank you, it works for my purposes. Can you explain why this is considered by Mathematica different evaluation or something? $\endgroup$
    – Kuba
    Aug 23, 2013 at 13:05
  • 1
    $\begingroup$ @Kuba, the message in the dialog says that a notebook contains a running evaluation. As I understand it, scheduled tasks are not associated with any specific notebook, so there is no reason for the front end to complain. $\endgroup$ Aug 23, 2013 at 13:53
  • $\begingroup$ Why not close all Untitled notebooks also? : RunScheduledTask[ Map[NotebookClose, Select[ Notebooks[], FreeQ[ NotebookInformation[#], "FileName"] & ]]; FrontEndExecute[FrontEndToken["FrontEndQuit"]]]; NotebookInformation[#], "FileName"] & ]]; $\endgroup$ Aug 23, 2013 at 16:35

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.