# Automatically close Mathematica

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"]]


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

-
@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. –  Kuba Aug 23 '13 at 11:21
By the way, isn't it strange that it offers to put the result to the MessageWindow since I'm closing MMA?:) –  Kuba Aug 23 '13 at 11:34
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. –  Pickett Aug 23 '13 at 14:29
When I want to automatically close Mathematica, I do ListPlot3D[bigdata] and try to rotate the view :D :D –  The Toad Aug 23 '13 at 14:44

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

FrontEndTokenExecute["FrontEndQuitNonInteractive"]

-
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 :) –  Kuba Aug 23 '13 at 18:39
@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. –  John Fultz Aug 26 '13 at 20:35
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. –  Kuba Aug 28 '13 at 10:03
@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. –  John Fultz Aug 28 '13 at 16:29
Thank you, I think it exhausts the topic. :) –  Kuba Aug 28 '13 at 18:08

As a workaround, try this:

1 + 1;
NotebookSave[EvaluationNotebook[]];

Why not close all Untitled notebooks also? : RunScheduledTask[ Map[NotebookClose, Select[ Notebooks[], FreeQ[ NotebookInformation[#], "FileName"] & ]]; FrontEndExecute[FrontEndToken["FrontEndQuit"]]]; NotebookInformation[#], "FileName"] & ]]; –  Rolf Mertig Aug 23 '13 at 16:35