I want to run some code automatically after saving my notebook. Is there a $ variable or setting for this?
Answer
Yes, it can be easily implemented with FrontEndExecute, e.g.:
SetOptions[EvaluationNotebook[], NotebookEventActions ->
{{"MenuCommand", "Save"} :> Print["HEY"], PassEventsDown -> True}];
You can insert any code instead of Print command
Edit
Above code executes Print["HEY"]
before saving the notebook, because you catch the event at the beginning, do some work and release it back to program with PassEventsDown
.
To evaluate some code after saving - one has to handle full event manually. The simplest would be just remove PassEventsDown
and instead of Print["HEY"]
write (NotebookSave[]; Print[123])
:
SetOptions[EvaluationNotebook[], NotebookEventActions ->
{{"MenuCommand", "Save"} :> (NotebookSave[]; Print[123])}]
Unfortunately, this will "intercept" also saving event triggered by "Save As" command and it will always save file with its old name even if we change name in "Save As" window.
Comments
Post a Comment