4
$\begingroup$

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.

$\endgroup$

2 Answers 2

4
$\begingroup$

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.

$\endgroup$
1
  • $\begingroup$ But this option would require a lot more work than simply evaluating a notebook myself. $\endgroup$
    – Anthony
    Commented Apr 10, 2013 at 20:04
4
$\begingroup$

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.

enter image description here

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]
$\endgroup$
6
  • $\begingroup$ I had already tried this and it didn't work :( $\endgroup$
    – Anthony
    Commented 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$
    – Anthony
    Commented 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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.