Mac Icons for PDFs

I have a great many folders of PDFs, mostly grabbed from magazine_rack, ataribooks, etc. The trouble is when I open a folder of these, Finder makes preview icons for a few of them, then gives up and they all show a generic "PDF" icon. What I want is a persistent icon for the first page!

First, you need osxutils:

% sudo port install osxutils
% man seticon

And my icontool.

sips (Scriptable Image Processing System) is a built-in tool on the Mac, incredibly powerful image converter. I'm not gonna do anything fancy with perspective ratios or padding, just use it to get an image.

Now create pdficonset.zsh:

find . -type f -d -iname "*.pdf" |while read -r f; do
    echo $f
    sips -s format png $f -o thumb.png && \
    icontool.zsh thumb.png thumb.icns && \
    seticon -d thumb.icns $f
    rm -f thumb.png thumb.icns

Run it in the parent directory, and boom! All nice icons.

[update: added a little better error-safety. CG_PDF_VERBOSE just gives better but still not useful error messages.]

I don't have the problem as bad with CBZ/CBR comics; they'd be trivial to extract the first page from, since they're just ZIP/BZIP files.

%d bloggers like this: