0
$\begingroup$

How do I execute code on save?

This is a similar question: Running a package automatically when it's saved

$\endgroup$
  • $\begingroup$ But you seem to be familiar with this procedure. Could you elaborate more then? $\endgroup$ – Kuba Apr 3 '15 at 21:50
0
$\begingroup$

Evaluating the following in a notebook will place a "toolbar" as a DockedCell with a Save and Run button:

SetOptions[EvaluationNotebook[], DockedCells -> 
  Cell[BoxData[ToBoxes[
    Row[
      {Button["Save and Run",
        Module[{},
          FrontEndTokenExecute[ButtonNotebook[], "Save"];
          NotebookFind[ButtonNotebook[], "Input", All, CellStyle];
          FrontEndTokenExecute[ButtonNotebook[], "EvaluateCells"]
        ]
       ]}, ImageSize -> Full, Alignment -> Right
    ]
   ]], 
  "DockedCell"
  ]
 ]

Afterwards, you can delete the above code, and then pressing this button will save the notebook before evaluating "Input" Cells.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Hmm. I was hoping there was an automatic way to do such. $\endgroup$ – William Apr 3 '15 at 21:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.