Saving a notebook without output lines

Is it possible to change the way Mathematica saves so that Out[] lines are never included?

I have a .nb file that processes a lot of data, and displays most of it as standard output. These graphs, tables, and intensity plots almost double the size of the file. I'd like to easily save these files in a smaller form and also prevent accidentally sending confidential results to users outside my company or not under an NDA.

That is, of course, without using Cell -> Delete All Output before each save. I can't be expected to remember to do that all the time! :-P

-

In Options Inspector you can change the EvaluationOptions for Selected Notebook or for Global Preferences by adding

{"WindowClose" :>  FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}

to the NotebookEventActions line.

Screenshots for changing the notebook evaluation options in Options Inspector:

A notebook with Input and Output cells and the Evaluation Options page in Option Inspector

After editing the NotebookEventActions line in Options Inspector or evaluating

SetOptions[EvaluationNotebook[], NotebookEventActions -> {"WindowClose" :>
FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];

inside the notebook:

After clicking X on the on the notebooks window frame:

After clicking Yes on the dialog window:

Alternative: you can add

SetOptions[EvaluationNotebook[], NotebookEventActions -> {"WindowClose" :>
FrontEndExecute[FrontEndToken["DeleteGeneratedCells"]]}];

to a notebook's initialization cell.

-
+1 This is probably a better solution than mine. It can be added at a per-notebook level while mine has to be global. Also, the final SetOptions approach is very quick to do. –  Simon Feb 23 '12 at 21:44

After making a backup of the MenuSetup.tr file, you can insert the following line somewhere in the Menu["&File"...] section:

MenuItem["Delete output and Save", FrontEndExecute[{
FrontEndToken["DeleteGeneratedCells"], FrontEndToken["Save"]}],

I placed it beneath the MenuItem["&Save"...] line. You can also change the key combination to something more memorable.

To see a list of all frontend tokens go to http://stackoverflow.com/a/4209612/421225

And the following code should give the location of MenuSetup.tr on all three supported platforms

With[{os = Switch[$OperatingSystem, "Unix", "X", "MacOSX", "OSX", "Windows", "Windows"]}, FileNameJoin[{$InstallationDirectory, "SystemFiles", "FrontEnd",