Dan Wood: The Eponymous Weblog (Archives)

Dan Wood Dan Wood is co-owner of Karelia Software, creating programs for the Macintosh computer. He is the father of two kids, lives in the Bay Area of California USA, and prefers bicycles to cars. This site is his older weblog, which mostly covers geeky topics like Macs and Mac Programming. Go visit the current blog here.

Useful Tidbits and Egotistical Musings from Dan Wood

Categories: Business · Mac OS X · Cocoa Programming · General · All Categories

Sat, 30 Dec 2006

A shell script to look in your receipts

Occasionally I want to find what package a particular Mac OS X tool was installed with. I don't want to make the mistake of calling a library or tool (using NSTask) that is only installed with developer tools.

For instance, you wouldn't want to have a non-developer Cocoa application invoke /usr/bin/atos because that is only installed as part of the developer tools, not part of the standard Mac OS X installation. On the other hand, /usr/bin/curl is standard on all Macs (at least in recent years).

How do you find out for sure? One way is to have a mac laying around without developer tools installed. Sorry, no-go for me! A better way is to look inside your receipts to see what package the tool in question was installed from. If it's in Essentials.pkg or BSD.pkg or BaseSystem.pkg, you can probably assume safely that all your users (at least on the version of the OS you are testing) have that tool available. If it's in some other package, you might have to ensure that the package in question (such as developer tools or a specific Apple-created application) is part of the system requirements for your program.

I have been trying to get comfortable in bourne shell scripting lately; here is my little script to find a string inside all of your computer's installation receipts (found in /Library/Receipts). I call it bomfind; use it like bomfind pattern.

#!/bin/sh

# Go to main receipts directory.  Does not search in home dir.
cd /Library/Receipts

for PKG in *.pkg
do
    pushd "$PKG/Contents" > /dev/null
    CONTENTS=`lsbom -s Archive.bom | grep $1`
    if [ ! -z "$CONTENTS" ]; then
        echo "$PKG:"
        echo "$CONTENTS"
        echo
    fi
    popd > /dev/null
done