Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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):

CreatePalette[
 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.


Addendum

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.

share|improve this question
    
I know this is not your real question, but for starters, ButtonNotebook[] returns $Failed in a fresh notebook and EvaluationNotebook[] doesn't –  Rojo Jun 27 '12 at 16:26
    
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[]]]}]; –  Rojo Jun 27 '12 at 16:30
    
@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. –  Szabolcs Jun 27 '12 at 16:30
    
Not everyone may know you're advanced, the first sentence could clarify that last point of yours –  Rojo Jun 27 '12 at 16:34
add comment

1 Answer

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.

share|improve this answer
add comment

Your Answer

 
discard

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.