0
$\begingroup$

Is there any way to get Mathematica to run a function each time I save a file? So either by ctrl-s or by the 'save' command in the file menu.

Then I could, for example, ask it to make a copy of the saved file in a different location each time I save it.

Thanks

$\endgroup$
0
1
$\begingroup$

You should be able to use NotebookEventActions for this:

CurrentValue[EvaluationNotebook[], NotebookEventActions] = {
    {"MenuCommand","Save"}:>Print[1],
    PassEventsDown->True
}

Replace Print[1] with your function.

$\endgroup$
1
  • $\begingroup$ Worth mentioning EvaluationOrder here, too. If they want the action to occur after the save (as is often the case) they'll need that. $\endgroup$ – b3m2a1 Aug 23 '18 at 0:35

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