Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to print to distiller folders in 10.2 UNIX

If someone wants to print to watched folders from within MacOS X 10.2, e.g. for feeding a distiller running in the Classic environment, they might try this CUPS backend [2kb download] that I wrote just for this purpose.

If the $DISTILLER variable is set to TRUE, then the backend will search for watched folders and provides them as "printer devices" in PrintCenter. When printing into such a "device", the resulting PostScript file will be saved in the appropriate "In" folder. If a file with that name already exists, a numerical suffix will prepend overwriting that file.

Installation is straightforward. Just copy the script into /usr/libexec/cups/backend/ and adjust $DISTILLER, $TARGET_BASEDIR (the backend will search only inside this path for hotfolders) and $MAX_FILENAME_LENGTH (filenames will be truncated to this value -- use 30 in conjunction with distiller). After restarting the cupsd process (either by sending it a SIGHUP signal or rebooting), every distiller hotfolder will be available as separate "printer device", so you can print directly into the folder without manually clicking through "save as" dialogs.

    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (1 vote cast)
 
[11,691 views]  

A script to print to distiller folders in 10.2 | 12 comments | Create New Account
Click here to return to the 'A script to print to distiller folders in 10.2' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to print to distiller folders in 10.2
Authored by: ssevenup on Mar 05, '03 06:28:35PM

Too cool, but your taking a massive amount of detail for granted. I got this to work, but here are just a few missing details...

Finding these "folders" as devices in Print Center requires holding the option key down while clicking the Add button and using the Advanced option.

What printer description to select? I chose a pretty generic Lexmark driver and it failed. The default "generic" driver seems to work, but I'm not sure what functionality (if any) I'm loosing.

What permissions the script and watched folders should use (if that matters).

It appears that the script is supposed to reset the permissions to 666 on the postscript after it moves it. Obviously it gets moved because Distiller is finding it and Distilling it, but the pdf's wind up root:admin with -rw-rw-r-- so I can't move or delete them. The .ps files wind up root:admin with -rw-rw-rw-. The debug line I'm seeing is the one right after the chmod line. So the permissions look like they are getting set by the script, but obviously I must not have permission to delete files that are group admin and 666.

In spite of the name checking, Distiller is overwriting my output files on every attempt. There seems to be no option in Distiller to avoid this either.

Armed with this information I plan to modify this script to work with PStill (if possible), so thank's for the tip.

--MM

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
A script to print to distiller folders in 10.2
Authored by: ssevenup on Mar 05, '03 11:21:36PM

A few additions...

I partially solved the permissions problem when I changed the permissions on the folders the watched folders were contained in.

The script was looking in the "watched folder/In" for the existing postscript files, but Distiller moves them into the "watched folder/Out". I tweaked the script to have it look there and it started appending the suffix as expected. PStill uses another scheme that I had to deal with also.

I modified the script to accomodate PStill, but since PStill allows any prefix to the preference file in the watched folder, some allowances had to be made. I could have used globbing to find them, but instead I just standardized the naming myself. This would be less than optimal for general consumption without detailed instructions.

I never figured out how to have both the PStill and Distiller watched folders available without combining the functions in the same shell script. That sounded like too much work to tackle today. I wasn't sure if the name of the shell script was important. In other words I never figured out if I could just have two different scripts in /usr/libexec/cups/backend, but it didn't appear that would work (i.e. the name appeared significant).

I don't have a public folder at my disposal, but if the original author or anyone else would like to see my shell scripts, I can email them. I welcome suggestions on more elegent to accomplish the same thing. I am still learning the art of shell scripting. Also, I would prefer a /bin/sh version of this (not that I actually tried just changing the !#)

I'm not sure how much more useful this is than PDF Services, but I like the idea of the option just appearing in the printer list. The geek quotient is higher ;-) I heard yesterday that OSX limits the "quality" of the output to 72dpi, and that only a few apps manage to force it any higher. Photoshop and Illustrator were mentioned. This makes me wonder just how useful all these cool PDF workflow tools are. This also explains why so many say that they get the best results with PDF if they use something like TexShop, which avoids the OSX print subsystem altogether.

mmoorcroft "at" mail.arc.nasa.gov

---
Mark Moorcroft
ELORET Corp. - NASA/Ames RC
Sys. Admin.



[ Reply to This | # ]
A script to print to distiller folders in 10.2
Authored by: Thomas Kaiser on Mar 06, '03 10:33:45AM
> Finding these "folders" as devices in Print Center requires
> holding the option key down while clicking the Add button
> and using the Advanced option.

I forgot that, thanks for the reminder...

> What printer description to select? I chose a pretty generic
> Lexmark driver and it failed. The default "generic" driver
> seems to work, but I'm not sure what functionality (if any)
> I'm loosing.

I would choose an Acrobat Distiller PPD that matches the version of the
used distiller.

> What permissions the script and watched folders should use
> (if that matters).

I could easily add the ability to change owner & group of the postscript
file. To do this, one would have to add a chown line after the chmod. I'll
add this.

> It appears that the script is supposed to reset the
> permissions to 666 on the postscript after it moves it.

Right.

> Obviously it gets moved because Distiller is finding it and
> Distilling it, but the pdf's wind up root:admin with
> -rw-rw-r-- so I can't move or delete them. The .ps files
> wind up root:admin with -rw-rw-rw-.

That's caused by the CUPS subsystem running under this account. I'll
change that to set the owner to originator of the printjob and the group
to a variable called "GROUP", that defaults to "staff"

> In spite of the name checking, Distiller is overwriting my
> output files on every attempt. There seems to be no option
> in Distiller to avoid this either.

Hmm... I tried the whole thing at a customer's site and this didn't occur
there. Maybe because he's using some custom startup procedures for
distiller. In case, distiller names the PDF derived from the %%Title:
comment in the PS-Job, it should be easy to fix that by preprending the
PostScript file with two lines... I'll look into it later.

> Armed with this information I plan to modify this script to
> work with PStill (if possible), so thank's for the tip.

Why is there a need for that? If you want low-end PDFs just use the ones,
the Quartz engine produces already.

Regards,

Thomas

[ Reply to This | # ]
A script to print to distiller folders in 10.2
Authored by: Stone_Design on Mar 06, '03 01:18:03PM
Actually, Mac OS X's PDF may produce high resolution PDF. For example, Create will print high resolution images at their full resolution, so PStill is very useful for several reasons:
  • You may want to convert the text to outlines
  • You may want to downsample & JPEG compress images
  • You may want to losslessly shrink the bloato PDF
  • You may want to chain various PS/PDF documents
  • You may want to scale a PDF to poster size

Anyway, I prepared a tutorial on how to add automated PDF Workflow - but I'll submit that as a separate hint! Andrew Stone, co-author of PStill

[ Reply to This | # ]

Modify for use without distiller
Authored by: stormer on Mar 06, '03 04:57:14AM

I am wondering if this script can be modified to work even without distiller.

For some purposes it would be nice to be able to just print a Postscript file for other uses. I notice that the script looks for a folder.joboptions file, can this be made optional?

Also, people should be aware that they need to make this script executable in order for it to work (or at least i had to) chmod +x should do the trick.

Thanks for a great script.



[ Reply to This | # ]
Modify for use without distiller
Authored by: Thomas Kaiser on Mar 06, '03 10:12:40AM
> I am wondering if this script can be modified to work even without
> distiller.

Sure. Just set the $DISTILLER variable to FALSE and specify via the
'device URI' where to store the postscript files as relative path to
$TARGET_BASEDIR.

So in case, you set $TARGET_BASEDIR to e.g. /Users/tk/Shared/ and
want to store the ps files in /Users/tk/Shared/ps-files/ then you should
set

    postscriptfile://ps-files

as 'device URI' in either PrintCenter or the CUPS web frontend.

> [...]
> Also, people should be aware that they need to make this script
> executable in order for it to work (or at least i had to) chmod +x
> should do the trick.

Hmm... seems to be a problem related to the decompression software.
Using curl & gunzip, the script should have proper permissions. I'm
thinking about providing a .dmg file with a small AppleScript based
installer instead when I finished some enhancements to the current
version...

Regards,

Thomas

[ Reply to This | # ]
Automagic pdf without Classic?
Authored by: mrhill on Mar 09, '03 05:31:38PM

This hint is wonderful, thanks!

I am attempting to kludge it to use ps2pdf13 (a part of ghostscript), and if I can get that up, it might be goodbye to classic (which I now use for Distiller).

Anyone know if there is a way to get the file and path names of the document being printed by the calling application? That might allow the script to be put right next to the document source file.



[ Reply to This | # ]
Automagic pdf without Classic?
Authored by: Thomas Kaiser on Mar 15, '03 06:11:56AM
I added some more features (to work with distiller, PStill and even GhostScript)

    http://user s.phg-online.de/tk/MOSXS/postscriptfile.gz

A brief description of the new version:

What is it?

The main purpose of this backend is to have the ability to print into
watched folders, so that output files can be postprocessed automatically
by tools like distiller, PStill, GhostScript, whatever...

How do I use it?

To use it you simply copy it into your CUPS backend folder (on MacOS X
usually /usr/libexec/cups/backend/), ensure, that it is executable and
restart the cups daemon (eg. by sending it a SIGHUP signal to reread it's
configuration)

Ah... and you'll have to configure a bit inside the script:

$TARGET_BASEDIR --> should be set as a "base dir" for hotfolders. All
paths are relative to that
$MAX_FILENAME_LENGTH --> defines how long filenames should be. This
is useful if you want to postprocess the files by e.g. distiller running in
the "classic environment"
$DEBUG --> set to TRUE to get some debug messages
$DEBUG_LOG --> This is where the backend will write log messages to
$GROUP --> this settings affects the group ownership of the files
$GS --> Specify the path to your GhostScript executable if you want to
drive the backend in ghostscript mode (see below)

Operational details:

The behaviour of the backend depends on how it is called. If you save it
as postscriptfile, than all it advertises when you invoke the PrintCenter
(while holding down [option]) is a basic print-to-disk "device". You have
to take care, that you encode the path names you want to use correctly.

If the backend will be called as "distiller", then it will advertise all
subfolders of $TARGET_BASEDIR that meet specific criteria (an "In"
folder and a folder.joboptions file inside). If it will be called as "pstill"
then it searches for a "ProcessedPS" folder and an options file, that ends
with ".pPref".

If called as "ghostscript" then it will look for a folder called "Finished" and
an options file called gs-options.txt. In this special case, it will not only
store the resulting PDF or PS file into the watched folder but instead
invoke GhostScript with the specific settings. For a detailed description
read below.

What if I want to use the backend for more than one sort of
postprocessing mechanism? Simply create symlinks to the basic
backend, as the functionality only depends on the name:

[imac-2:/usr/libexec/cups/backend/] tk# ls -la
lrwxr-xr-x 1 root wheel 14 Mar 15 09:42 distiller -> postscriptfile
lrwxr-xr-x 1 root wheel 14 Mar 15 09:42 ghostscript -> postscriptfile
-rwxr-sr-x 1 root wheel 6958 Mar 15 11:02 postscriptfile
lrwxr-xr-x 1 root wheel 14 Mar 15 09:42 pstill -> postscriptfile

How to drive GhostScript?

As there currently doesn't exist a hotfolder scheme for GhostScript, we
simply define our own :-)

Create inside $TARGET_BASEDIR a new folder, containing a subfolder
called "Finished" and a simple textfile called gs-options.txt. In this file
you write the settings you want gs to use, eg.

-q
-dNOPAUSE
-dBATCH
-r2400
-sDEVICE=pdfwrite
-dPDFSETTINGS=/prepress
-dProcessColorModel=/DeviceCMYK
-dCompatibilityLevel=1.3

(It's strongly recommended that you always use the "-q", "-dNOPAUSE"
and "-dBATCH" options because otherwise unexpected behaviour will
occur)

For a more detailled description of the settings consult the GhostScript
documentation please.

Does this make sense at all?

Maybe ;-)

You should know, how printing in MacOS X works. Applications have
basically two ways to create output that will be postprocessed by printer
drivers:

- PostScript (as we know it from former MacOS releases)
- PDF (the "standard" way in MacOS X)

As PDF is the basic technology for the Quartz display engine, most apps
simply create printer output by using Quartz. The result is a PDF file
(a mixture between PDF 1.2 and 1.3) that can be opened directly by any
any PDF 1.3 aware viewer or renderer.

When printing through CUPS these PDF files will be converted to
PostScript when the specific printer queue has been assigned a PPD file
(as it happens always when you use the PrintCenter for adding new
printers). Search for a line with "cgpdftops" at the top of such PS files, to
be sure how it has been created.

Those applications that produce still PostScript output directly (mostly
from the desktop publishing sector), will write "pictwpstops" instead in
the "%%Creator: " comment.

As you see, normally you will convert PDFs from PDF to PostScript
(invoked by a CUPS filter) and then after leaving the spooling system
back to PDF by a postprocessing mechanism. Doesn't makes always
sense, except you're using applications that produce PostScript...

Thomas Kaiser, 2003/03/15

[ Reply to This | # ]
New and enhanced version available
Authored by: Thomas Kaiser on Mar 20, '03 05:59:57PM
Just in case, anyone finds this useful...

I added direct support for "PDF Enhancer" hotfolders (can be used to
optimize, encrypt, linearize, etc.) and some sort of "PlugIns". If the
backend finds executable files called "actionscript-pre" or
"actionsscript-post" in one of the watched folders, these will be executed
either before or after the PDF/PS files have been saved.

This might be useful for the following tasks:

Before saving a PS file one might want to modify the PS Code by a script
(ie. inserting custom PDFmarks that can be processed by distiller or
ghostscript)

After saving the files, they should be emailed automatically or uploaded
to ftp-servers or whatever you want.

You'll find some examples here.

The backend can be downloaded at the usual location.

Regards,

Thomas

[ Reply to This | # ]
New and enhanced version available
Authored by: FredB on Jul 22, '03 02:54:32AM

I was wondering if anyone could point me in the right direction on where to go for professional script development?



[ Reply to This | # ]
Mostly Panther compatible.
Authored by: osax on Jan 06, '04 11:00:56AM

This script seems to work in Panther. The only problem is that it somehow cannot get the Hot Folder names from the printer device URI.

This line doesn't work:
PARSED_URI=`echo ${DEVICE_URI} | perl -ple 's/%([0-9A-Fa-f]{2})/chr(hex($1))/eg'`

However, this fragment works from the shell; so i'm stumped as why it won't work from within the backend. Can anyone help?

BTW: Thanks for the great script!



[ Reply to This | # ]
Mostly Panther compatible.
Authored by: Thomas Kaiser on Apr 03, '04 11:59:21AM
Simply change the shebang line (the first line that determines the executing process/shell) from "#!/bin/sh" to "#!/bin/bash" to regain the full functionality. Details can be found in the updated docs.

Currently I'm working on a new version (supporting PSNormalizer Framework, Quartz filters, and other features as well) including a graphical installer that will do the job for you. I'll get back to here, when I'm finished.

Maybe you've feature requests? Then it's time to write them down :-)

Regards,

Thomas

[ Reply to This | # ]