I have a print button connected to a text view. If I click the print button or press Command-P the standard print window appears and it prints OK.
The problem is that I want to do some preparation before I print.
What I want to accomplish is:
When the user clicks the “print” button then:
First: Prepare the text view to be printed.
Second: Show the Print dialog.
If I define the print-button in a handler, the preparation is done but the print dialog does not appear.
I could define two buttons: a prepare print button and a print button but I think that is a very clumsy solution. There must be a better way.
Could it be done with just one button?
Thanks in advance for any support.
The code below will evaluate a text view, do something with it (a simple string append), update the text, and then print it. To allow the cocoa system to actually see the text view as the object of the command, make sure the call method is within a “tell” block correctly identifying the text view. If you want your print menu item to perform this action, rather than the standard application print command, just disconnect it from the default connection and hook up the menu item to this AS code instead.
on clicked theObject
if name of theObject is "printButton" then
tell text view "tV" of scroll view "sV" of window "win"
set preProcess to contents
set postProcess to (preProcess & return & return & "jobu was here") as string
set contents to postProcess
call method "print:" of object it
Hope this helps,