Skip to main content
2 of 2
added 1 characters in body
rm -rf
  • 89.3k
  • 21
  • 297
  • 480

The following definition to $Pre will save a copy of your notebook as filename.nb.backup.nb, where filename.nb is your original notebook and strip it of all output cells every time you evaluate a cell.

$Pre = With[
    {nb = NotebookPut[NotebookGet[EvaluationNotebook[]]]},
    FrontEndExecute[{
        FrontEnd`NotebookFind[nb, "Output", All, CellStyle, AutoScroll -> False], 
        FrontEnd`FrontEndToken["Clear"]
    }];
    NotebookSave[nb, NotebookFileName[] <> ".backup"];
    NotebookClose[nb];
    #
] &
rm -rf
  • 89.3k
  • 21
  • 297
  • 480