Monday, October 29, 2007

PS Printing in Leopard

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:

  1. Add a generic printer using Printer Preferences Pane
  2. Open a web browser and navigate to http://localhost:631
  3. Navigate to the printers tab
  4. Choose Modify Printer
  5. Step through the process configuring the printer as you would have in the Print Center Advanced options.
Following this process I was able to add back the printer, which unfortunately was not able to print :(.

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

Friday, October 26, 2007

Meow...

Ok installing Leopard was a little more complicated that I thought! 

The main problem related to a lack of resources...

Yes, thats right, we were nearly out of diesel and with the current diesel shortage finding some so we could get home was an issue :)

Ok, now seriously. Install = insert DVD, double click (install icon), enter username/password, click, click, click, wait, wait, click, done. It ... well ... just worked.

Total time almost 2hrs. Validating the DVD took 1hr, install took 1hr.

I did need to login with my admin account to finish the registration. Most apps are working, though I found that Menu Shades doesn't... 

Alpha Geek

Last launch party I went to was for Windows 98... which was a bit disappointing, and as Raj reminds me took me until 4 in the morning to install. If I remember correctly... the issue was drivers for my SCSI HDD.

So does it make me a Geek to say that even though I should be home in bed (... I'm not well), tonight I'll be there at the Leopard "Launch Party" down at the nearest store?

I hope so :)

More details once this Tiger has gone, and a Leopard takes its place. That is assuming the update goes to plan... I'm dreaming right... this never really works... Well I'll let you all know soon enough.

Thursday, October 25, 2007

Whats up?

Well I haven't blogged for a while... and I just found a nice little Blogger Widget that allows me to post from Dashboard.

So what exciting has happened lately? Well not much, actually. The semester went slowly at the start but the last few weeks have really shot by.

In OOP the SwinTrek assignment appears to have causes some students issues, but those who really put in the effort are now showing the benefits. I definately think the assignment has proven itself in terms of learning outcomes.

Advanced .NET is crusing along. The students are now starting to push themselves. Maybe I need to make the assignments due a bi earlier.

Well thats enough for now. If your studying one of my subjects please let me know what you think...