MACSCRPT Archives

March 2010

MACSCRPT@LISTSERV.DARTMOUTH.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Steve Alex <[log in to unmask]>
Reply To:
Macintosh Scripting Systems <[log in to unmask]>
Date:
Wed, 3 Mar 2010 14:03:16 -0600
Content-Type:
text/plain
Parts/Attachments:
text/plain (47 lines)
I knew if I posted something that, even though it worked,  I'd get a response or two on how to improve it. Even saw quit a few names I recognized from the past.

I ended up converting to cups-pdf, which I think is basically a virtual printer that implements gostscript and ps2pdf.

Had a little trouble getting it to work on snow leopard and then I had the classic problem of making sure a file exists and was completely written.

My Safari stuff was reduced to:

	tell application "Safari"
		open location "file://" & htmlPath
		set name of document of window 1 to filename # what cups-pdf uses to name file
		print window 1 with properties {target printer:"PDF-Writer"}
		close window 1
	end tell

I still found it best to use System Events to make sure the print file was done. The basic pseudo code is something like:

	tell application "System Events"
		repeat with i from 1 to 15
			set printers to (name of every application process where name is "PrinterProxy")
			if the number of printer proxies is equal to the number at start
				it's done writing the file, exit repeat
			end if
			delay 1
		end repeat
	end tell

Takes about 3 seconds to write out a 1meg PDF.

Thanks for the suggestion.

Steve Alex

On Mar 2, 2010, at 9:00 PM, John Delacour 

>     print window 1 with properties {target printer:"my virtual printer"}
> 
> The print files are spooled to /var/spool/cups/, which requires root access.
> 
> Then convert the resulting PostScript file to pdf using ps2pdf
> 
>  (do shell script "man ps2pdf")
> 
> for which you need ghostscript, which is not a troublesome installation.
> 
> Otherwise Preview will automatically convert ps to pdf on opening.

ATOM RSS1 RSS2