Wednesday, 18 September 2013

AppleScript: Add or Create New Keychain

The following AppleScript allows you to add or create new a Keychain entry.

<<AppleScript>>

set _account to the text returned of (display dialog "User name" with title "Keychain by Andres Cheah, MCM" with icon note buttons {"OK"} default button 1 default answer "")
set _password to the text returned of (display dialog "Password" with title "Keychain by Andres Cheah, MCM" with icon note buttons {"OK"} default button 1 default answer "" with hidden answer)
try
set _creator to "apsr" -- Abbrevation for AppleScript
set _keychain to "Application"
set _app_keychain to "/Applications/Utilities/Keychain Access.app"
set _ac to _account & "@ABC.local"
set _label to "Twitterrific"
set _srvr to "Twitterrific"
set _pw to _password
do shell script ¬
"/usr/bin/security add-generic-password " & ¬
" -a " & _ac & ¬
" -l " & _label & ¬
" -c " & _creator & ¬
" -s " & _srvr & ¬
" -w " & _pw & ¬
" -T " & quoted form of _app_keychain & ¬
" -A " & _keychain
display dialog "You have added your Keychain successfully. Click OK to exit." with title "Keychain by Andres Cheah, MCM" with icon caution buttons {"OK"} default button 1
end try

No comments:

Post a Comment