I'm trying to figure out how to print a message dialog without printing the whole notebook. FrontEndExecute[FrontEndToken["PrintDialog"]] displays the print window (just like selecting file -> print but it prints the whole notebook. I have also tried using FrontEndExecute[FrontEndToken["PrintSelectionDialog"]] but when the code is run the selected area becomes unselected.

I have solved part of the problem with the following

  DialogNotebook[{Column[{Plot[Sin[x], {x, 0, 6 Pi}], 

This prints the entire window including the print button as shown.
print output
This is exactly what I am looking for but without the print button.
Any ideas much appreciated,

  • $\begingroup$ If you mean a message dialog that you code yourself. Consider creating a notebook on the fly that you format, size, and configure to operate as a message dialog. A bit of a heavy handed workaround but that should give you all the flexibility you need. Easier to answer if you give more a specific example and some code. $\endgroup$ – Jagra Aug 2 '12 at 19:45
  • $\begingroup$ Your question is not too well specified. I tried to provide a couple of general examples below, but if you will give more context for your problem I will try to be more specific myself. $\endgroup$ – Mr.Wizard Aug 2 '12 at 22:14
  • $\begingroup$ I appreciate the update. I tried to find a solution to print everything but the button but I could not. Hopefully someone with FrontEnd expertise will be able to. $\endgroup$ – Mr.Wizard Aug 5 '12 at 7:41

It is not clear to me from your question how you want to use this operation. If you create a Button with this code you should be able to click the button to print a selected block of code.

Button["Print Selection",
  FrontEndTokenExecute @ "PrintSelectionDialog"

If you want to perform this operation programmatically you need to control the selection with e.g. SelectionMove.

 SelectionMove[EvaluationNotebook[], All, EvaluationCell];
 FrontEndTokenExecute @ "PrintSelectionDialog"

You can move the selection to a different Cell or Notebook if needed. In addition to the documentation for SelectionMove read: Manipulating Notebooks from the Kernel.

| improve this answer | |
  • $\begingroup$ Thanks for the help. In the end I created a button to execute NotebookPrint[CreateDocument[stuff to be printed]] $\endgroup$ – Christina Aug 16 '12 at 15:43
  • $\begingroup$ @Christina you're welcome; I'm sorry I didn't have something more specific for you, but I'm glad you found something that works for your application. $\endgroup$ – Mr.Wizard Aug 17 '12 at 0:53

Is this what you are looking for?

PrintMessage[expr_] := NotebookWrite[MessagesNotebook[],
| improve this answer | |
  • $\begingroup$ Since Mr.Wizard's answer was accepted with the fact it does something different than yours, I think your answer isn't on topic. But I agree the question itself may be vague. $\endgroup$ – Kuba Apr 15 '15 at 7:22
  • $\begingroup$ True, but the key idea was "how to print a message dialog", which wasn't really answered. $\endgroup$ – M.R. Apr 15 '15 at 19:15
  • $\begingroup$ +1 Not sure what the OP was really looking for, but when I searched for writing to the Message window, this answer came up, and that's what I was looking for. $\endgroup$ – bobthechemist May 24 '15 at 12:25

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.