I know how to run multiple notebooks at once. But my problem is that due to the RAM capacity, I have to run these notebooks consecutively. Another problem is that since I may not be in my office all the time, I want these notebooks to be run automatically. For example, notebook1 is evaluated, then notebook2 is evaluated, and so on.

Is there any way to do this? Any idea would be appreciated.

  • 1
    $\begingroup$ see NotebookEvaluate $\endgroup$ – george2079 Sep 8 '15 at 18:45
  • $\begingroup$ Thanks, but I don't want to evaluate notebooks with in a kernel. Actually, I have 4 notebooks in 4 separate kernels, and I want to evaluate them sequentially. $\endgroup$ – Alex Sep 8 '15 at 18:59
  • 2
    $\begingroup$ How would you know (or the other kernels, for that matter) know when an evaluation has finished ? $\endgroup$ – Sektor Sep 8 '15 at 20:15
  • 1
    $\begingroup$ I suspect the best approach is to use a shell script for the looping and command line launch mathematica to eval each notebook. Saving will be a trick. Is it feasable to put some save code in each notebook? $\endgroup$ – george2079 Sep 8 '15 at 21:13

If you really need to do everything in the frontend, then I would Suggest the below procedure, in this process Mathematica would open a new window selects all the cells and runs them then it would go for the second notebook file

nb1 = NotebookOpen["/Users/you/Documents/1.nb"];
SelectionMove[nb1, All, Notebook]
nb1 = NotebookOpen["/Users/you/Documents/2.nb"];
SelectionMove[nb1, All, Notebook]

Hope this will help

Second Approach

If you are using OS X you can use the shell script

first give the path to the Mathematica then run the kernel to run your scripts remember you need to save them as .m files as save as option wont work alone you have to convert them to standard form cmd+8 in OS X if I'm not wrong.


"$math" -script 1.m

"$math" -script 2.m

And you need complete path to .m files by the way!

  • $\begingroup$ Thanks, but the first approach runs two notebooks at the same time. While, as I mentioned before, I want them to be evaluated sequentially. $\endgroup$ – Alex Sep 10 '15 at 0:38
  • 1
    $\begingroup$ you are mistaken! It does open them simultaneously, but starts running the cells one by one! Starting from the first opened notebook file add the command Pause[10] in to first notebook and watch. The second notebook file is open but it's waiting for the first notebook to be evaluated. To be sure I checked again. Good luck $\endgroup$ – Sarah Aria Sep 16 '15 at 0:34
  • $\begingroup$ well as sarah said, you are wrong. $\endgroup$ – Raymond Ghaffarian Shirazi Sep 19 '15 at 23:34
  • $\begingroup$ Thank you @RaymondGhaffarianShirazi and @Sarah! I have another question. I have 24 runs that I'd like to allocate a maximum time (e.g., 2 hours) to each run. So, I'll need 48 hours, but if I distribute these 24 runs among 4 kernels, the whole computations can be done in 12 hours. How can I do that? Any help/idea would be appreciated! $\endgroup$ – Alex Oct 9 '15 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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