0

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

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
Jojo
  • 1,278
  • 8
  • 19

1 Answers1

1

You should be able to use NotebookEventActions for this:

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

Replace Print[1] with your function.

Carl Woll
  • 130,679
  • 6
  • 243
  • 355
  • Worth mentioning EvaluationOrder here, too. If they want the action to occur after the save (as is often the case) they'll need that. – b3m2a1 Aug 23 '18 at 00:35