Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've already written code that generates about 20 notebooks using "CreateDocument" and I was wondering if there exists a method to automatically save them. Is there an easy way to create a notebook and save it programatically, i.e. without manually saving the notebook?

share|improve this question
up vote 12 down vote accepted

NotebookSave is your friend, it's usage is quite straightforward:

nb = CreateDocument[{"hello"}];
NotebookSave[nb, FileNameJoin[{$HomeDirectory, "Desktop", "tst.nb"}]]

If you didn't save the NotebookObject that CreateDocument returns to a variable you can use Notebooks[] to get that, the following is an example that selects by WindowTitle:

nb = Select[Notebooks[], 
        AbsoluteCurrentValue[#, WindowTitle] === "Untitled-1" &][[1]]
share|improve this answer
Beat me by seconds. +1 – rcollyer Mar 5 '13 at 20:15
@rcollyer: I bet your answer would have been somewhat more elaborate, though :-) – Albert Retey Mar 5 '13 at 20:17
Not in this case. I probably would have linked to the docs, and given a very bare bones answer. – rcollyer Mar 5 '13 at 20:25

Your Answer


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.