[NOTE: - this is part two of a three-part tip. Please see Part 1 for background info.]

Try as I might, I couldn't find a simple utility to access the Keychain from the command line. So I wrote one. Download it and install it somewhere on your system. Then you call it like so:

% keychain name account

It will look up the specified key of kind "application password" with the name and account given in the default keychain, and emit it to standard out.

Source code is available. If you want to compile it yourself, install the Developer Tools, then create a new project of type Tool -> CoreServices Tool. Name the project "keychain." Double-click main.c and replace it with the contents of main.c downloaded from my website. Click Build to build the project. Then command-drag the resulting executable to your desktop or wherever you'd like to place it.