I have a few questions for how the feature NotebookDynamicExpression was used in ResourceFunction[SetNotebookAutoSaveTime]. Below is the entire definition:
SetNotebookAutoSaveTime[] :=
SetNotebookAutoSaveTime[EvaluationNotebook[]];
SetNotebookAutoSaveTime[nb_NotebookObject] :=
SetNotebookAutoSaveTime[nb, 60];
SetNotebookAutoSaveTime[n_] /; NumberQ[n] || n === None :=
SetNotebookAutoSaveTime[EvaluationNotebook[], n];
SetNotebookAutoSaveTime[n_Quantity] :=
SetNotebookAutoSaveTime[EvaluationNotebook[], n];
SetNotebookAutoSaveTime[nb_, n_?NumberQ] :=
SetOptions[nb,
NotebookDynamicExpression ->
If[n > 0, Dynamic[Refresh[NotebookSave[nb], UpdateInterval -> n]],
Inherited]];
SetNotebookAutoSaveTime[nb_, None] :=
SetOptions[nb, NotebookDynamicExpression -> Inherited];
SetNotebookAutoSaveTime[nb_, n_Quantity] :=
With[{qm = QuantityMagnitude[UnitConvert[n, "Seconds"]]},
SetNotebookAutoSaveTime[nb, qm] /; NumberQ[qm]];
However I wish to only focus on these three lines:
SetNotebookAutoSaveTime[n_] /; NumberQ[n] || n === None :=
SetNotebookAutoSaveTime[EvaluationNotebook[], n];
SetNotebookAutoSaveTime[nb_, n_?NumberQ] :=
SetOptions[nb,
NotebookDynamicExpression ->
If[n > 0, Dynamic[Refresh[NotebookSave[nb], UpdateInterval -> n]],
Inherited]];
SetNotebookAutoSaveTime[nb_, None] :=
SetOptions[nb, NotebookDynamicExpression -> Inherited];
In the documentation the author writes, "Notebooks only auto-save if they have been saved once and have changed in memory." But I also notice that author uses NotebookSave[nb]
. Does NotebookSave[nb]
monitor if edits have been made? If not, where in the code does that take place? How might this action be started and stopped with a toggle button?
SetNotebookAutoSaveTime[None]
afterwards will NOT actually stop the periodic autosaving, which is a bit more worrisome. $\endgroup$