Thursday, February 08, 2007

Postscript Automator Actions

Having played with Automator some yesterday I thought it would be interesting to create an Automator action to perform the Postscript manipulation. This would mean that I could package the scripts together in a workflow to make producing the PDFs for my subjects even easier...

Creating an Automator action is actually quite easy. It basically uses an architecture inspired by Unix pipes. You can pass output from one action to the input of the next. I decided to create script actions as I already had the bash script all worked out. With this script the input is passed via the standard input. Automator also allows you to provide arguments via a simple user interface. These arguments are then passed in as environment variables. The following script illustrates the Postscript to PDF Automator action...



#!/usr/bin/env sh

if [ -e "$PS2PDFBIN" ]; then

while read line; do

if [ -e "$line" ]; then
FILETYPE=`/usr/bin/file -b -i "$line"`
if [ "$FILETYPE" = "application/postscript" ]; then

OUTDIR=`/usr/bin/dirname "$line"`
FBASE=`/usr/bin/basename "$line" .ps`
OUTNAME="${OUTDIR}/${FBASE}.pdf"

typeset -i I=1

while [ -e $OUTNAME ]
do
OUTNAME="${OUTDIR}/${FBASE}.$I.pdf"

I=$I+1
done

PATH=$PATH:`/usr/bin/dirname "$PS2PDFBIN"`
$PS2PDFBIN -q -sPAPERSIZE="$PAPER" -dNOPAUSE -dBATCH -sDEVICE=pdfwrite "$line" "$OUTNAME"

/bin/echo "$OUTNAME"
else
/bin/echo $line
fi

else
/bin/echo $line
fi
done
else

echo "Cannot locate executable: '$PS2PDFBIN'" 1>&2
exit 1
fi

I will upload the action bundles soon if anyone is interested...

8 comments:

Anonymous said...

This is exactly what I've been looking for! I'm surprised that capability is not offered from Preview since does postscript to pdf conversion.

Could you post or send me the bundle? kwb7@mac.com

Thanks!

Kevin

Anonymous said...

does this mean that ps2pdf can files of different dimensions and produce all 8.5x11 PDFs as a final product??

Andrew Cain said...

From my recollection this will scale the output to the indicated paper size. ps2pdf allows you to specify the output size, where as the standard apple pstopdf outputs to 8.5x11 only. I use ps2pdf as I want output primarily as A4.

Anonymous said...

<< I will upload the action bundles soon if anyone is interested...>>

Yes, please. I'm interested.

Chris Beard said...

Yes, I too am very, very interested

Unknown said...

<< I will upload the action bundles soon if anyone is interested...>>

Yes, please. I'm also interested.

bernat3rs@hotmail.com

Anonymous said...

The scripts are available as Automator actions from:

Convert_PS_to_PDF.action.zip

and

Convert_PS_to_Multipage_Output.action.zip

Unknown said...

Hi Andrew,
Thank you. I downloaded this 2 files and I added them to Automator but it seems that I need GhostView and ps2pdf.
I found all of this but I'm confused about the creation of the workflow to covert PS to PDF.
If you have time, could you help me with that ?

Thanks,
Bernat