I have a Mathematica 6 course that I am using in Mathematica 9; there is no updated version. Every time I open a notebook I have to go to the Evaluation menu and click on "Evaluate Notebook". Is there a way for me to set it so that it automatically evaluates a notebook upon my opening it? I keep getting answers on shortcuts I can use once the notebook is open or pressing shift-enter on a cell but that's not an answer; I would like not to do anything at all other than open the notebook and have every cell evaluated already since the tutorial course is long and contains a ton of notebooks.
2 Answers
One thing you could do would be to make a master notebook with lots of
NotebookEvaluate[notebook]
commands. Then execute all the ones you'll need at the start in one group. Then when you open them, they'll already be evaluated. You could do this programmatically by reading in and evaluating all the notebooks in a directory.
-
$\begingroup$ But this option would require a lot more work than simply evaluating a notebook myself. $\endgroup$– AnthonyCommented Apr 10, 2013 at 20:04
With the option inspector (shiftctrlO) you can set the value of the option InitializationCellEvaluation
to True
(make sure that you select "Global Preferences"). Setting InitializationCellWarning
to False
suppresses the dialog you would normally get. Please note that this may entail a potential security issue.
You can do it programmatically as well:
SetOptions[$FrontEndSession,
InitializationCellEvaluation -> True,
InitializationCellWarning -> False
]
I used$FrontEndSession
here, so that the effect lasts for the session only (safer), but if you want to make this more permanent you could change that to $FrontEnd
.
UPDATE
Assuming that you have all the notebooks in one directory dir
, you could open and evaluate them all at once by using:
NotebookEvaluate /@ NotebookOpen /@ FileNames["*.nb", dir]
-
$\begingroup$ I had already tried this and it didn't work :( $\endgroup$– AnthonyCommented Apr 10, 2013 at 20:03
-
$\begingroup$ @anthony I was assuming your notebooks would have initialization cells, but apparently they don't. $\endgroup$ Commented Apr 10, 2013 at 20:23
-
$\begingroup$ @Anthony Perhaps the update meets your requirements? $\endgroup$ Commented Apr 10, 2013 at 20:40
-
$\begingroup$ Unfortunately this would open hundreds of notebooks; I only go through certain notebooks as needed. $\endgroup$– AnthonyCommented Apr 12, 2013 at 18:00
-
$\begingroup$ @Anthony I suggest that you do a ctrl-a shift-return upon opening a notebook. Those two key presses should be easy to perform. Or is that too much effort for you? $\endgroup$ Commented Apr 12, 2013 at 18:35