scripting printing from BBEdit or Print Center in osx

I know there have been similiar questions here, but the answers haven’t helped me exactly. Other than using “Page Sender”, is there a way to script OSX, specifically BBEdit to print to a PDF file (or ps file for that matter)?

I have set up a “virtual printer” as recommended in this post, but when I try this I get Print Center spinning forever with an “Attempting to connect to printer ‘localhost’” error, even though if I manually go through the print dialogs it works fine.

I guess what I’m asking for is if anyone knows how to set some kind of print settings variables that can pass things like ‘save as PDF’ and a filename for such options.

All I’m trying to work out is the following simplified version with my default ‘vitual printer’ already set up, so I can work this functionality into a bigger script that will print multiple open auto-generated BBEdit files:


tell application "BBEdit"
	print text window 1 without print dialog
end tell

I am new here, and I hope these questions are not too silly. :oops:

Thank you.