# Automatically Created Documents don't have safety dialogs on close?

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:

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.

## 1 Answer

Set the ClosingSaveDialog option in the created notebook:

nb = CreateDocument[TextCell[ExampleData[{"Text", "LoremIpsum"}], "Text"]];
SetOptions[nb, ClosingSaveDialog -> True]

• 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. – Reb.Cabin Apr 13 '16 at 18:10
• @Reb.Cabin I suppose adding whatever option works then. – Kuba Apr 13 '16 at 18:31
• @Reb.Cabin, yes I expected the option to work directly in CreateDocument. Not sure if it's this way by design or a bug. – Simon Woods Apr 13 '16 at 18:41
• @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 ;). – Kuba Apr 14 '16 at 7:42
• SimonWoods no wait, @Reb.Cabin wants an automatic solution and it is such. Just rephrase it. – Kuba Apr 14 '16 at 7:48