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


Click here to return to the 'Got it working with ~/Desktop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Got it working with ~/Desktop
Authored by: BrunoUsesBBEdit on Dec 11, '03 01:20:59PM
Great work!!!

But, I had a big problem with "PDF Printing" not showing up in my list. The problem was that all of the double quotes were backslashed in the code sample in the main hint body.

I also went ahead and solved the problem of allowing the printer to be specified with a Device URI of PDF://~/Desktop to get it to print on the users desktop or PDF://~/Documents... etc.

And I made the log more concise while I was at it.


#!/bin/sh
#
# Michael Goffioul
# Updated by P T Withington for Mac OS X
# Updated by Richard Bronosky

LOGFILE=/tmp/PDF.log
GSBIN=/usr/bin/pstopdf
FILENAME=

echo "Script:           $0" > $LOGFILE
echo "Executable:       $GSBIN" >> $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
  if [ ! -x "$GSBIN" ]; then
    exit 0
  fi
  echo "direct PDF \"Unknown\" \"PDF Writing\""
  exit 0
fi

# case of wrong number of arguments
if [ $# -ne 5 -a $# -ne 6 ]; then
  echo "Usage: PDF job-id user title copies options [file]"
  exit 1
fi

# get PDF directory from device URI, and check write status
PDFDIR=${DEVICE_URI#PDF:}
if [ `echo $PDFDIR|cut -c1-3` = //~ ]; then
  PDFDIR=/Users/$2`echo $PDFDIR|cut -c4-`
  # This step added by Richard Bronosky to allow referencing the users home directory
fi
if [ ! -d "$PDFDIR" -o ! -w "$PDFDIR" ]; then
  echo "ERROR: directory $PDFDIR not writable"
  exit 1
fi

echo "PDF directory:    $PDFDIR" >> $LOGFILE

# generate output filename
OUTPUTFILENAME=
if [ "$3" = "" ]; then
  OUTPUTFILENAME="$PDFDIR/unknown.PDF"
else
  OUTPUTFILENAME="$PDFDIR/${3//[^[:alnum:]]/_}.PDF"
fi

echo "Output file name: $OUTPUTFILENAME" >> $LOGFILE

# run ghostscript
if [ $# -eq 6 ]; then
  $GSBIN $6 -o $OUTPUTFILENAME >> $LOGFILE
else
  $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
  chown $2 $OUTPUTFILENAME
fi

exit 0

---

--==< B r u n o >>==--

[ Reply to This | # ]

Got it working with ~/Desktop
Authored by: whiteinge on Jan 15, '04 04:46:51PM

Thanks Bruno, that really hooked me up!



[ Reply to This | # ]