I am looking for a concrete code example where EvaluationNotebook[] and ButtonNotebook[] will return different results.

The docs for ButtonNotebook say:

If a button in a palette initiates evaluation in another notebook, then ButtonNotebook[] will be the palette, but EvaluationNotebook[] will be the other notebook.

How can a palette button initiate an evaluation in a different notebook?

A basic test where they return the same (the palette):

 Button["press", Print@{EvaluationNotebook[], ButtonNotebook[]}]]

I am looking for an example where EvaluationNotebook and ButtonNotebook return different results when invoked from the same button. Of course ButtonNotebook will return $Failed when not invoked from a button.


I'd like to point out that this question is not merely of theoretical interest. The fact that ButtonNotebook exists at all suggests that it must be different from EvaluationNotebook in some non-trivial way. Understanding the behaviour of EvaluationNotebook/ButtonNotebook is important to create robust code that will work correctly in edge cases too. I can not see their difference, so there must be some edge case I have not thought of.

  • $\begingroup$ I know this is not your real question, but for starters, ButtonNotebook[] returns $Failed in a fresh notebook and EvaluationNotebook[] doesn't $\endgroup$
    – Rojo
    Jun 27, 2012 at 16:26
  • $\begingroup$ There's even an example in the EvaluationNotebook docs of your point where they use EvaluationNotebook to refer to the button notebook: pal = CreatePalette[{Button["Test", NotebookWrite[InputNotebook[], "Done"]; NotebookClose[ EvaluationNotebook[]]]}]; $\endgroup$
    – Rojo
    Jun 27, 2012 at 16:30
  • $\begingroup$ @Rojo That's of course the trivial difference. I didn't mention it because I thought it was clear that I'm interested in the case when the code is invoked from a button. $\endgroup$
    – Szabolcs
    Jun 27, 2012 at 16:30
  • $\begingroup$ Not everyone may know you're advanced, the first sentence could clarify that last point of yours $\endgroup$
    – Rojo
    Jun 27, 2012 at 16:34

1 Answer 1


John Fultz posted an answer to this question here. Apparently, in this context, both ButtonNotebook and EvaluationNotebook are identical. The former is kept around for legacy purposes, but the latter is preferable because it is applicable in places other than in buttons.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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