Automatically mount AFP for Time Machine (without saving a password in plaintext)

Here's how you can pull the password out of the Keychain in OS X.

pw=$(security find-internet-password -wl mntpt)

This presumes the item is stored in the keychain with the name "mntpt"

Then you should be able to use your script on the next line:

mount -t afp afp://user:[email protected]/location /Volumes/mntpnt