0

Suppose I have an action like follows:

ClearAll[eventAction];
eventAction[]:=Module[{
    $previousPath,
    $todaysPath
},
    $previousPath=NotebookFileName[EvaluationNotebook[]];
    $todaysPath=FileNameJoin[{
        NotebookDirectory[],
        "NameChangingNotebook - "<>DateString[Today,{"Day","Month","YearShort"}]<>".nb"
    }];
    NotebookSave[EvaluationNotebook[],$todaysPath]
    DeleteFile[$previousPath]
];

How do I make this action execute whenever the notebook save command is sent?

DynamicModule[{},EventHandler[Null,{{"MenuCommand","Save"}:>(eventAction[])}]];
user13892
  • 9,375
  • 1
  • 13
  • 41
  • FrontEndToken[EvaluationNotebook[], "Save"] is not working here. Maybe some complex frontend knowledge is required for this task. You can try a binding with the shortkey like Ctrl + S in Windows. – bcegkmqs23 Jan 25 '20 at 15:05
  • Is NotebookEventActions the answer? – Kuba Jan 25 '20 at 18:38
  • @Kuba sorry I don't have access to desktop notebook frontend right now. But if you can try and find out whether it works in the following command or any other command do let me know as well.

    SetOptions[EvaluationNotebook[],NotebookEventActions->{"WindowClose":>(eventAction[])}]

    – user13892 Jan 25 '20 at 19:06

0 Answers0