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?
1 Answer
$\begingroup$
$\endgroup$
3
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]]
-
-
$\begingroup$ @rcollyer: I bet your answer would have been somewhat more elaborate, though :-) $\endgroup$ Commented Mar 5, 2013 at 20:17
-
1$\begingroup$ Not in this case. I probably would have linked to the docs, and given a very bare bones answer. $\endgroup$– rcollyerCommented Mar 5, 2013 at 20:25