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


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 )


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"]


I have a Mathematica package that provides auto-backup functionality. When enabled, the current notebook--call it "blah.nb"--will be backed up to "blah.nb~" after a configurable amount of time has elapsed. I use it constantly and it has saved me from losing work many, many times. It's better than autosaving since it doesn't touch the actual notebook file: if you screw something up or something gets corrupted you don't want to overwrite your main file. :)

It's on GitHub here.

链接地址: http://www.djcxy.com/p/35538.html

上一篇: 每个程序员应该阅读哪本最有影响力的书?

下一篇: 自动保存笔记本(或mathematica中的其他类型文件)文件