[IPython-User] feature request : auto save ipython notebook file

Fernando Perez fperez.net@gmail....
Thu Mar 22 18:05:27 CDT 2012

On Thu, Mar 22, 2012 at 3:44 PM, Brian Granger <ellisonbg@gmail.com> wrote:
> We are working on this one.

But note that what we're discussing is a *background* autosave, that
would save the notebook with a *different* filename than the real one,
to be used only in case of a crash.  What the OP is asking for is an
autosave that automatically saves the notebook he is working on
directly, and that's something I've said multiple times I absolutely
will not have on by default, because it risks saving a state that may
be unwanted. Since we have no undo/history capability, this would be

Fortunately, the OP can have autosave right now, just put this in your
startup file:

def autosave(interval=5):
    """Autosave the notebook every interval (in minutes)"""
    from IPython.core.display import Javascript
    interval *= 60*1000 # JS wants intervals in miliseconds
    tpl = 'setInterval ( "IPython.notebook.save_notebook()", %i );'
    return Javascript(tpl % interval)

and call it anywhere in your notebook to activate it.

Alternately, just put this (in this case, using 5 minutes):

<script type="text/javascript">
setInterval ( "IPython.notebook.save_notebook()", 5*60*1000 );

in the first cell of your notebook and make it a markdown cell.
You're done, autosave is on for that notebook everytime you open it.

Remember: you have full access to the notebook 'application' itself
from within javascript, so if there's something we don't yet provide
with a UI element ourselves, it's likely just a few lines of code away
for you.



More information about the IPython-User mailing list