This script provides an example of Keychain scripting. From the AppleScript Users List.
OS version: OS X
set theShortUserName to do shell script "/usr/bin/whoami" --get the short
userid. This is how your default keychain is labled.
tell application "Keychain Scripting"
set myKeyChain to keychain theShortUserName
set theKeyList to every Internet key of myKeyChain --email keys are
normally Internet Keys
repeat with x from 1 to (length of theKeyList)
set theKey to item x of theKeyList
if the name of theKey is "name of key here" then
set thePassword to password of theKey --grab the password
set theUserID to the account of theKey --grab the userid
end if
end repeat
end tell