Re: Printing to PDF via GUI scripting.
Re: Printing to PDF via GUI scripting.
- Subject: Re: Printing to PDF via GUI scripting.
- From: Philip Aker <email@hidden>
- Date: Tue, 04 Feb 2003 09:52:29 -0800
On Tuesday, February 4, 2003, at 08:07 AM, Schaaf, Bob wrote:
I'm looping through a folder of text files which must be opened in
BBEdit,
reformatted, printed to PDF, and closed.
Having used System Events to do Page Setup and Print, with Default
Folder X
to set the destination folder, I've run into a real problem between
dismissing the Save dialog and closing the file.
Printing is asynchronous! After the Save button is clicked, the script
continues and tries to close the file, which is still in use (i.e. PDF
conversion). The whole script hangs.
I would be possible to put in a "delay" statment, and this works, but
is
inelegant. Further, these print files are of variable size, and it
would be
difficult to determine the delay time. I don't want to us an arbitrary
large number. (GUI scripting can be painfully slow. Tried selecting a
menu
item from a pop up button?)
Is these any way to determine when the printing process terminates, and
resume execution only then?
I installed ESP GhostScript. It works with CUPS. I think I could now
print a Dagwood sandwich to PDF if paid. :)
Anyway, to print the files from an AppleScript, use a 'do shell script'
for 'lp' and get the current printer jobs with 'lpstat'. They both have
man pages. You may also stop a particular job or all jobs on a
specified printer with the 'cancel' command.
set res to (do shell script "lp " & "/path/to/file.ext;lpstat")
should return your job id. If you call 'lpstat' say in an idle handler,
you'll be able to determine that all the jobs in the current queue are
done when it returns nothing. The manuals are at:
<
http://localhost:631>.
HTH,
Philip Aker
http://www.aker.ca
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.