One approach that's slightly hacky but works really well is to run two NSPrintOperations.
We use this in our app's printing code, to detect if the user selected a regular printer or a receipt printer in the print panel. The app prints an entirely different document for each kind of printer.
So in PyObjC, untested code:
def smartlyPrintView_(self, theViewToPrint):
# set up and run an initial NSPrintOperation to get printInfo
fakePrintOperation = NSPrintOperation.printOperationWithView_(theViewToPrint)
NSPrintOperation.setCurrentOperation_(fakePrintOperation)
if NSPrintPanel.printPanel().runModal() == True:
# get the printInfo so we can do stuff with it
printInfo = fakePrintOperation.printInfo()
# get rid of our fakePrintOperation
NSPrintOperation.currentOperation().cleanUpOperation()
# do stuff
# run a real NSPrintOperation without a printPanel
realPrintOperation = NSPrintOperation.printOperationWithView_printInfo_(theViewToPrint, printInfo)
realPrintOperation.setShowsPrintPanel_(False)
realPrintOperation.runOperation()
else:
NSPrintOperation.currentOperation().cleanUpOperation()
Recipe to translate this to Obj-C:
Add some variable declarations, replace the underscores with colons, and interleave the arguments with the method's clauses. Mix in half a cup of flour and a handful of semi-colons. Simmer at low heat for thirthy minutes and serve hot. Good luck :)