# Run a command each time a file is saved [duplicate]

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

You should be able to use NotebookEventActions for this:
CurrentValue[EvaluationNotebook[], NotebookEventActions] = {

Replace Print[1] with your function.
• 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 0:35