Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically saving notebook (or other type files in mathematica) files

I have been facing this problem for sometimes now, a laziness caused in part by the fact that Microsoft Office automatically save files you are working on with versions and automatic recovery.

Many times when I am starting a new notebook in mathematica to do some tests or whatever, I often forget to save what I am doing.

Every now and then, depending on the computer I am using, the computer crashes and all the beautiful work I was doing is lost forever...

Is there a way to get around this other that manically saving my files every five minutes? How about file versioning?

BTW: Using MMA V8

like image 787
Phil Avatar asked Aug 25 '11 16:08

Phil


2 Answers

Regarding autosaving, you may want to check out the NotebookAutoSave option, which can be set to True through Fromat->Option Inspector. You have to choose "Selected notebook", then go to Notebook Options -> File Options, and set NotebookAutoSave to True. Then, your notebook will be saved after every evaluation. Whether or not this is a satisfactory solution, of course depends on the situation.

But my experience is that the most reliable way is to develop a CTRL+S reflex - this one never lets me down and is working quite well.

As for the versioning, it is much easier with packages, for which you can use WorkBench which has integrated support for CVS and support for SVN via Eclipse plugin. For notebooks, I refer you to this SO thread. You may also find this Mathgroup discussion of some interest.

EDIT

For M8, for auto-saving purposes you can probably also run

RunScheduledTask[NotebookSave[EvaluationNotebook[]],{300}]

But I can not test this code at the moment

EDIT2

I just came across this post in the Toolbag repository - which may also be an alternative for the autosave part of the question (but please see also the discussion in comments on the relative advantages of scheduled tasks vs. Dynamic)

like image 136
Leonid Shifrin Avatar answered Sep 28 '22 10:09

Leonid Shifrin


Since you have MMA version 8 you could use:

saveTask = CreateScheduledTask[FrontEndExecute[FrontEndToken["Save"]], 5*60];
StartScheduledTask[saveTask];

to save every 5 minutes (change the term 5*60 for other timings).

To remove the auto-save task use:

RemoveScheduledTask[saveTask];

To save only a fixed, specific notebook, store its handle in nb (finding it using Notebooks, SelectedNotebook, InputNotebook or EvaluationNotebook) and use FrontEndToken[nb,"Save"] instead of just FrontEndToken["Save"]

like image 39
Sjoerd C. de Vries Avatar answered Sep 28 '22 09:09

Sjoerd C. de Vries