Quite some time ago, I needed to create a script which would mount a network volume. I did not want to hardcode username and password into the script, so I kept looking for ways to accomplish this using OS X’s built-in Keychain. The following example uses a script to mount a network volume, using variables for the currently logged-in user, and fetches its password from the Keychain. Of course, you can do other things with this approach, so I figured it might be of use to someone out there.
The following is a combination of these 2 links:
http://hintsforums.macworld.com/showthread.php?t=163359
http://blog.macromates.com/2006/keychain-access-from-shell/
This script gets the password for the currently logged in user and pulls its password from the Keychain. It then mounts a share using the variables without hardcoded …
Source: Mac OSX Hints