Inspired by this post I've been trying to implement the idea in Wolfram with no success yet. I've come pretty close though and need some help. So I've managed to do this:
NotebookSave[
Notebook[{
Cell[BoxData@MakeBoxes[
f = NotebookFileName[]; NotebookClose[EvaluationNotebook[]];
DeleteFile[f]
], "Input"]
}
, NotebookDynamicExpression :>
Refresh[FrontEndTokenExecute[EvaluationNotebook[],
"EvaluateNotebook"], UpdateInterval -> 0]
, InitializationCellWarning -> False]
, FileNameJoin[{$UserBaseDirectory, "SelfDestruct"}]
]
It saves the notebook to trusted directory with self destruct code in the input cell and it has dynamic expression that evaluates the notebook. Now the stupid question is how to prevent opening this notebook with NotebookSave
or what would be the trick here? Because it immediately self destructs, but I want to preserve the file and do a self destruction later of course.
EDIT: Maybe there is a better way to do this? I also wonder whether it's possible to make self destructing CDF so it would work with just CDF Player installed.
DeleteFile
with something else, then edit the notebook in an external editor to restoreDeleteFile
? $\endgroup$