Hello, I’ve been reading, with great interest, about printing active window contents. See this older thread http://bbs.applescript.net/viewtopic.php?id=9446 I have the code working for my project and it looks very nice. I had to re-make the form by hand in interface builder because my original vector PDF just wasn’t printing out cleanly. But in any case, my area of interest at the moment is using the call method for “print” without having to display the dialog first. I’ve found another method called “showPrintPanel” from “NSPrintOperation”. But I must admit, as I don’t completely understand what I’m doing with the call method operations or how to set them up, I don’t know how to figure this out. Is it possible to bypass the print dialog by using call method “print:”?
The code I’m trying is
tell window "print_window"
set visible to true
activate
tell box "print_box"
set sharedPrintInfo to call method "sharedPrintInfo" of class "NSPrintInfo"
set setShowsPrintPanel to call method "setShowsPrintPanel" of class "NSPrintOperation"
call method "setLeftMargin:" of sharedPrintInfo with parameters {0.0}
call method "setRightMargin:" of sharedPrintInfo with parameters {0.0}
call method "setTopMargin:" of sharedPrintInfo with parameters {0.0}
call method "setBottomMargin:" of sharedPrintInfo with parameters {0.0}
call method "showsPrintPanel:" of setShowsPrintPanel with parameters {false}
call method "print:" of it
end tell
end tell
The error I receive is: The variable setShowsPrintPanel is not defined. (-2753)
A very talented friend that I work with found a way to suppress the print setup dialog and go straight to printing the job. However, I don’t believe it can be done with the “print:” method. It requires setting up the print job with several other call method commands. Here is the obj-c calls that need to be made to suppress it. First set up your form as you want it to print, inside an NSBox. Thanks also go to jobu and others for steering me on to this method. This prints only the form contents, as opposed to the entire window, including close/minimize buttons, title bars, etc. Then, do the following;
tell window "print_window"
tell box "print_box"
set thePrinter to (call method "printerWithName:" of class "NSPrinter" with parameter printerName) -- Change printerName to your printer name
call method "setPrinter:" of sharedPrintInfo with parameter thePrinter
-- Set paper size
set theSize to (call method "pageSizeForPaper:" of thePrinter with parameter "Letter") -- "Tabloid"
if (item 1 of theSize > 0) then call method "setPaperSize:" of sharedPrintInfo with parameter theSize
-- Get box's view
set theView to (call method "contentView" of object it)
-- For debugging enable the line below. This will send a PDF to Preview instead of printing it
--call method "setJobDisposition:" of sharedPrintInfo with parameter "NSPrintPreviewJob"
-- Create the print operation and execute it
set thePrintOp to (call method "printOperationWithView:printInfo:" of class "NSPrintOperation" with parameters {theView, sharedPrintInfo})
call method "setShowPanels:" of thePrintOp with parameter "NO"
if ((call method "runOperation" of thePrintOp) ≠1) then display dialog "Printing failed." buttons {"OK"} default button 1 with icon caution
end tell
end tell
Thanks everyone who has contributed to this solution, either directly or indirectly via other posts here at macscripter.net. This site is a tremendous resource.
What I’m wondering now, is if somebody can tell me the process for specifying a scale for the print. I’m trying to fit my window onto a vertical DL sheet.