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.

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
add comment

1 Answer 1

up vote 10 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
1  
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
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.