Whither thee launchd?

Unfortunately, for a number of reasons, I’ve been far too busy to follow up my previous post to use Mac OS X’s launchd to detect when the Sony eReader connects. There’s a lot of good launchd stuff on the Web, though, and it promises to be pretty easy once I sit down and actually write a plist for it.

In the mean time, here’s a revised script for moving the printed PDF files from a spooling directory to the eReader on connection. The setup is the same as before; simply kick the script with a Folder Action.

#!/usr/bin/env sh
PATH=/opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export PATH

readermain="/Volumes/PRS 700"
readercard="/Volumes/700 CARD"
spool="/Users/kf6gpe/.cups-pdf-spool"
pdfdest="$readercard/PDFs/"

growl()
{
    message="$*"
    which growlnotify > /dev/null
    if [ $? -eq 0 ]; then
        echo $message | growlnotify -t "eReader" -p -2 -a /Applications/Preview.app
    fi
}

if [ -f "/tmp/prs-busy" ]; then
    exit 0;
fi

if [ -d "$readercard" ]; then
    touch /tmp/prs-busy
    growl "Device detetected.";
    for f in `ls $spool/*.pdf`
    do
        cp $f "$pdfdest"
        if [ $? -eq 0 ]; then
            rm -f $f
            growl "Transferred `basename $f`."
        fi
    done
    growl "PDF transfer complete.";
    rm /tmp/prs-busy
else
    rm /tmp/pre-busy 2>&1 /dev/null
fi
exit 0

The changes are pretty self-explanatory. In brief:

  1. Have use Preview’s icon, in case Calibre isn’t installed.
  2. Only look for the eReader’s card; there’s really no reason to look for both volumes. 
  3. Use the lock file /tmp/prs-busy to ensure that the actual movement of the files doesn’t occur while it’s actually running. 

Of these changes, (3) was certainly the most important, because if you mounted another volume (say, a digital camera) while the script was doing things, weird things could happen. In practice, I never saw anything amiss, but this makes me sleep better at night.

Better printing to the Sony eReader using CUPS-PDF

After the recent work I’ve done integrating my Sony eReader with Mac OS X, I still wanted to be able to optimize page layout for the device. 

After some digging around and realizing that I don’t have ppdc I grabbed a PPD file for a generic Postscript printer and started hacking. 

Download ereader.ppd

The results work pretty well, although I see goofy margins from some applications such as TextMate.

Next up? Ditching the Folder Action script I wrote about yesterday in favor of launchd.

Improving Interaction Between the Sony eReader and Mac OS X

I have always read a ridiculous amount. Sadly, in recent years as I’ve taken greater advantage of resources such as the Association for Computing Machinery‘s Digital Library, what that really means is that I print a lot.  There’s a definite advantage to paper; you can stick it in your bag, or put your feet up and lean back more so than with a laptop or desktop PC. At the same time, I don’t archive what I read on paper; I either make notes citing the papers I’ve read, or if the paper is really important to me, I archive a copy of the PDF itself. As a result, my professional reading workflow is one of researching, printing, reading, and recycling the results. This is a tremendous waste of paper.

While I’ve tried various ebook solutions on PDAs over the years, I’ve never been particularly happy with PDF handling on mobile devices.  I’ve watched with interest the growing market for ebooks on devices including the Sony eReader and the Amazon Kindle, although until recently neither has had particularly good PDF handling either.

Last month I laid hands on a Sony eReader, and really liked what I saw. PDF presentation with later firmware in the PRS 505 is much improved over previous firmware releases, and both the PRS 505 and PRS 700 support Secure Digital cards. As USB devices, these products show up as a mass storage device when mounted on Mac OS X. As an added bonus, Kovid Goyal’s Calibre application supports both format translation and automatic harvesting of Web content from RSS feeds. I have to admit that it’s pretty spiffy to get up in the morning, grab the eReader from my desk and have the latest content from both The New York Times and The Economist at my fingertips. In conjunction with the large number of freely available books from Feedbooks, it’s a leisure reader’s dream.

Although the eReader’s appearance as a mass storage device in the Mac OS X Finder is useful, I quickly tired of downloading papers and manually copying them to the device. Intuitively, it seemed that what I wanted to be able to do was to treat the eReader as another printer.

Upon reflection, this idea is quite compelling. It doesn’t require me to change my work flow at all; moreover, there is something cool about the idea of an eInk device being directly accessible as a printer.

Continue reading Improving Interaction Between the Sony eReader and Mac OS X