Printing to PDF from a script

I’ve found that GUI scripting the Print Dialog rarely, if ever, works for me. Today, I saw the solution:


(*
1) Go to http://www.codepoetry.net/projects/cups-pdf-for-mosx
    	CUPS-PDF is a backend module for CUPS (Mac OS X's printing system) 
   	by Volker C. Behr that, rather than printing to a device, prints 
    	straight to PDF files that appear in a folder on your desktop.
2) Download and install the package (requires an admin password)
3) Follow the simple instructions on the CodePoetry site
*)

property OP : missing value
tell application "Printer Setup Utility"
	set OP to current printer
	set current printer to printer "Virtual Printer"
end tell

-- later on after getting your pdf files by printing to the Virtual Printer
delay 3 -- you can watch to check that this works in the Printer List window

tell application "Printer Setup Utility" to set current printer to OP

Hint for those who need access to the damn popup button of the print dialog (ie, print to postscript or whatever PDF service): you can use XTool’s mouse commands to click it (and use System Events to guess the location of such popup button).