5
$\begingroup$

If I manually open a new DocumentNotebook in the front end using the GUI, and then I put input in the document, and then try to close the document, I get a safety dialog asking me whether I want to save the document:

enter image description here

If I create a new DocumentNotebook using the CreateNotebook symbol, put something into it, however, I can close the notebook and I don't get the safety dialog. I want to force such automatically created notebooks to have a safety dialog.

At first blush, it looks like the contents I'm inserting into the created notebook are not inputs (no In[47]:= notation on the left). So perhaps a better question is "How can I automatically insert input into an automatically created notebook?" The key, here, is "automatically;" I want to do this without any manual interaction with the front-end GUI.

enter image description here

$\endgroup$
4
$\begingroup$

Set the ClosingSaveDialog option in the created notebook:

nb = CreateDocument[TextCell[ExampleData[{"Text", "LoremIpsum"}], "Text"]];    
SetOptions[nb, ClosingSaveDialog -> True]
|improve this answer|||||
$\endgroup$
  • 1
    $\begingroup$ verified that adding the option to the inside of the call to CreateDocument did not work; it seems necessary to add the option after-the-fact with a call to SetOptions. $\endgroup$ – Reb.Cabin Apr 13 '16 at 18:10
  • $\begingroup$ @Reb.Cabin I suppose adding whatever option works then. $\endgroup$ – Kuba Apr 13 '16 at 18:31
  • $\begingroup$ @Reb.Cabin, yes I expected the option to work directly in CreateDocument. Not sure if it's this way by design or a bug. $\endgroup$ – Simon Woods Apr 13 '16 at 18:41
  • $\begingroup$ @SimonWoods The fact that dialog is prompted doesn't seem be related to that specific option but to the fact that you are modifying the notebook. You can use SetOptions[nb, Background -> Red] and it will be equally good, except the fact of the red background ;). $\endgroup$ – Kuba Apr 14 '16 at 7:42
  • $\begingroup$ SimonWoods no wait, @Reb.Cabin wants an automatic solution and it is such. Just rephrase it. $\endgroup$ – Kuba Apr 14 '16 at 7:48

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.