Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:

      f = NotebookFileName[]; NotebookClose[EvaluationNotebook[]]; 
      ], "Input"]
  , NotebookDynamicExpression :> 
     "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.

share|improve this question
Just a wild guess, but can't you, e.g., replace DeleteFile with something else, then edit the notebook in an external editor to restore DeleteFile? – LLlAMnYP Mar 9 at 10:30
@LLlAMnYP Yeah it works, but kinda feels wrong :) – swish Mar 9 at 10:34

Use Export[file, your-nb-expression, "NB"] instead of NotebookSave.

share|improve this answer
Yeah! It works! I tried Export before but without NB, I thought it doesn't work, thanks! – swish Mar 9 at 10:42
@swish Glad it worked for you. Yours is pretty inventive code, by the way. Nice! – Leonid Shifrin Mar 9 at 10:44
I thought it will fix my problems but unfortunately it won't, could you take a look at 109651? – Kuba Mar 10 at 14:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.