Back in February I created some Automator scripts to automate the process of printing and publishing my lecture notes. These scripts hinged on the ability to use a small printer script that send the printer output to file, simple ps script. Upgrading to Leopard has caused me some issues in this regard.
The first issue is the fact that the Print Center has been removed. In the past you could Option click the Add Printer button to enable the Advanced options. With the new Printer Preferences Pane this option has been removed. So my first issue was adding the printer back at all. After some searching I found that the cups process can be administered remotely using http://localhost:631. To create the new printer you can do the following:
- Add a generic printer using Printer Preferences Pane
- Open a web browser and navigate to http://localhost:631
- Navigate to the printers tab
- Choose Modify Printer
- Step through the process configuring the printer as you would have in the Print Center Advanced options.
On Tiger the cups process is run by the root user, however on Leopard the security has been tightened and now the printer is run using a low privilege account, _lp. My old postscript saving scripts would output the file to any folder you chose, and then alter the ownership to the calling user. The new script can no longer do this. I've listed the new script below for anyone interested the corrected script. Please note that you will need to setup the printer with reference to a location that can be written to by this user, I have used /tmp.
I'll look into this again later, but for the moment this meets my needs. Other suggestions are welcome.
---
#!/bin/sh
#
# Michael Goffioul
# Updated by P T Withington for Mac OS X
# Updated by Richard Bronosky
# Updated by Steve Palm (N9YTY) - case insensitive URI, unique output files
# Recreated as PS copy by Andrew Cain
LOGFILE=/tmp/psprinter.log
FILENAME=
CPBIN=/bin/cp
ECHOBIN=/bin/cat
RUNAS=`/usr/bin/whoami`
echo "Script: $0" > $LOGFILE
echo "Run as: $RUNAS" >> $LOGFILE
echo "job: $1" >> $LOGFILE
echo "user: $2" >> $LOGFILE
echo "title: $3" >> $LOGFILE
echo "num-copies: $4" >> $LOGFILE
echo "options: $5" >> $LOGFILE
echo "filename: $6" >> $LOGFILE
# case of no argument, prints available URIs
if [ $# -eq 0 ]; then
echo "direct PS \"Unknown\" \"PS Writing\""
exit 0
fi
# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
echo "Usage: ps job-id user title copies options [file]"
exit 1
fi
# get ps directory from device URI, and check write status
URI_PRE=`echo $DEVICE_URI | cut -c 1-2 | tr "[a-z]" "[A-Z]"`
URI_BODY=`echo $DEVICE_URI | cut -c 3-`
DEVICE_URI="${URI_PRE}${URI_BODY}"
echo "Device URI: $DEVICE_URI" >> $LOGFILE
PSDIR=${DEVICE_URI#PS:}
if [ `echo $PSDIR|cut -c1-3` = //~ ]; then
PSDIR=/Users/$2`echo $PSDIR|cut -c4-`
# This step added by Richard Bronosky to allow referencing the users home directory
fi
echo "PS DIR: $PSDIR" >> $LOGFILE
if [ ! -d "$PSDIR" -o ! -w "$PSDIR" ]; then
echo "ERROR: $PSDIR not writable" >> $LOGFILE
echo "ERROR: directory $PSDIR not writable"
exit 1
fi
echo "ps directory: $PSDIR" >> $LOGFILE
# generate output filename
OUTPUTFILENAME=
if [ "$3" = "" ]; then
OUTPUTFILENAME="$PSDIR/unknown.ps"
else
OUTPUTFILENAME="$PSDIR/${3//[^[:alnum:]]/_}.ps"
fi
FBASE=`basename ${OUTPUTFILENAME} .ps`
typeset -i I=1
while [ -e $OUTPUTFILENAME ]
do
OUTPUTFILENAME="${PSDIR}/${FBASE}_$I.ps"
I=$I+1
done
echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE
# move ps to destination
if [ $# -eq 6 ]; then
echo "copy $6 $OUTPUTFILENAME"
$CPBIN $6 $OUTPUTFILENAME >> $LOGFILE
# $GSBIN $6 -o $OUTPUTFILENAME >> $LOGFILE
else
#cp /dev/stdin $OUTPUTFILENAME
echo "$ECHOBIN - >> $OUTPUTFILENAME"
$ECHOBIN - >> $OUTPUTFILENAME
# $GSBIN -i -o $OUTPUTFILENAME >> $LOGFILE
fi
# modify ownership and permissions on the file
# - world readable
# - owns to user specified in argument
chmod a+r $OUTPUTFILENAME
if [ "$2" != "" ]; then
echo "Change ownership with: chown $2 $OUTPUTFILENAME" >> $LOGFILE
chown $2 $OUTPUTFILENAME
fi
exit 0
1 comment:
http://advertising.microsoft.com/gatineau
Check it out!
Post a Comment