0
$\begingroup$

How do I execute code on save?

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

$\endgroup$
1
  • $\begingroup$ But you seem to be familiar with this procedure. Could you elaborate more then? $\endgroup$ Commented Apr 3, 2015 at 21:50

1 Answer 1

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.

$\endgroup$
1
  • $\begingroup$ Hmm. I was hoping there was an automatic way to do such. $\endgroup$ Commented Apr 3, 2015 at 21:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.