Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
@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
1  
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
6  
When I want to automatically close Mathematica, I do ListPlot3D[bigdata] and try to rotate the view :D :D –  rm -rf Aug 23 '13 at 14:44
add comment

2 Answers

up vote 15 down vote accepted

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

FrontEndTokenExecute["FrontEndQuitNonInteractive"]
share|improve this answer
1  
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
1  
@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
add comment

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.

share|improve this answer
    
Thank you, it works for my purposes. Can you explain why this is considered by Mathematica different evaluation or something? –  Kuba Aug 23 '13 at 13:05
1  
@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. –  Simon Woods Aug 23 '13 at 13:53
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.