I'm using DynamicModule with Manipulate to save the state of the manipulated variables in the notebook across sessions, and that works well most of the time. However, there's one flaw: it appears that even though the values of the variables are saved with the notebook, changes to those values don't count as changes to the notebook as reflected in the "ModifiedInMemory" property. This means when I quit Mathematica without saving the notebook, I'm not prompted to save it and can accidentally lose changes.

Here's a simplified example:

  Dynamic["ModifiedInMemory" /. NotebookInformation @ SelectedNotebook[]]]
    {u, 0, 1},

As I move the slider, ModifiedInMemory doesn't change to True, and I can quit without being prompted to save.

Is there a way to get the behavior I want, that moving the slider sets ModifiedInMemory so that I'm prompted to save on exit?

  • $\begingroup$ I'd ask WRI Support if this behavior is intended or not. $\endgroup$ – Kuba Sep 3 '18 at 5:12

You would just have to change something in the notebook which triggers the "ModifiedInMemory" notebook-property whenever the dynamic code in the Manipulate is evaluated. I doubt that there is documentation available which exactly lists which actions do that, the following is one example that will do it:

  SetOptions[EvaluationCell[],CellTags->ToString[AbsoluteTime[], InputForm]];
  {u, 0, 1},
  UndoTrackedVariables :> {u}

using the menu entry "Cell" "CellTags" "Show Cell Tags" you can see what it does.

  • $\begingroup$ Thanks. I would put that in the category of "workaround", but I'm not averse to that. It seems that it's not actually necessary to change the value, i.e. just setting to the same string e.g. "changed" every time works. However there is one flaw: when you first open the notebook it looks like that block of code gets executed, so it appears as if you've made a change (e.g. prompted to save when exiting) when in fact all that's happened is the previous value has been restored. Not a showstopper, but hoping for something a bit better. $\endgroup$ – Bruce Lucas Sep 3 '18 at 2:11
  • $\begingroup$ Sure, that is a workaround. But as the default behavior is what it is that is all we can provide. Maybe someone else finds something that works better, but changing or adding to the default behavior is something only WRI can do. Hope it is of some help anyway... $\endgroup$ – Albert Retey Sep 3 '18 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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