2

I want a notebook to automatically save after any cell is evaluated. I found that I should use the command

SetOptions[XXX, NotebookAutoSave -> True]

to do that, where XXX should be referring to the current notebook. Unfortunately, I have been searching the web for half an hour now and was not able to find the command which refers to "this notebook". I tried $FrontEndSession, $FrontEnd and even $Notebooks and nothing helped. Therefore, my question is:

What refers to "this notebook" within the SetOptions command?

Kagaratsch
  • 11,955
  • 4
  • 25
  • 72
  • 1
    EvaluationNotebook[ ]? – Dr. belisarius Mar 03 '16 at 16:32
  • @Dr.belisarius If I exectue SetOptions[EvaluationNotebook[], NotebookAutoSave -> True], write a new cell afterwards and exectue it, the file stays unsaved. – Kagaratsch Mar 03 '16 at 16:34
  • 1
    nb = EvaluationNotebook[]; SetOptions[EvaluationNotebook[], NotebookAutoSave -> True]; Options[nb, NotebookAutoSave] Returns True – Dr. belisarius Mar 03 '16 at 16:39
  • @Dr.belisarius The problem is, it only saves if at least one cell in the notebook has no semicolon, so that an output is produced. If the output of all cells is suppressed with semicolons, and I write a new cell suppressed with semicolon - an evaluation will not save the file. – Kagaratsch Mar 03 '16 at 16:48
  • 2
    That is exactly by design: NotebookAutoSave is a notebook option which specifies whether the notebook should automatically be saved after each piece of output generated by evaluation in it. – Dr. belisarius Mar 03 '16 at 16:51
  • Oh, I see, OK! Thank you! Your solution EvaluationNotebook[ ] works. – Kagaratsch Mar 03 '16 at 18:18
  • If a function doesn't produce output it doesn't make sense to save the file at that point as nothing will have changed (output suppressed by a semicolon is not invisibly written in the file; it's simply not there, it's only present in the kernel). – Sjoerd C. de Vries Mar 03 '16 at 18:43
  • @SjoerdC.deVries When I edit a notebook through the front end, I expect Mathematica to realize that the notebook has been changed. If it does not do that and stores all actions in the Kernel only, it is doing something wrong in my opinion. – Kagaratsch Mar 03 '16 at 22:20
  • We're talking about autosaving based on finishing an evaluation, not editing. If the evaluation doesn't produce output then also manually saving would not store your result as there isn't anything added to the FrontEnd. – Sjoerd C. de Vries Mar 03 '16 at 22:37
  • @SjoerdC.deVries OK. I am mostly interested in saving input lines $\textit{before}$ the evaluation even starts, since they can get lost if a calculation hangs up the computer and I have to do a hard restart. – Kagaratsch Mar 04 '16 at 00:06
  • 1
    @Kagaratsch Oh! I asked about that some time ago http://mathematica.stackexchange.com/q/8761/193 – Dr. belisarius Mar 04 '16 at 01:07

1 Answers1

3
nb = EvaluationNotebook[]; 
SetOptions[EvaluationNotebook[], NotebookAutoSave -> True]; 
Options[nb, NotebookAutoSave]

(* True *)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453