AppleScript Library

Keychain Library

   Some handlers to facilitate the access to logins and passwords stored in Mac OS keychains via AppleScript.

All handlers displayed on this page were freely available on the internet or written by myself. Please refer to the copyright section at the end of this page. Feedback appreciated.


AppleScript Editor open download

Properties
myName
General
getLoginAndPasswordForKey

Properties

property myName

Name that should be used when loading this library.

show source AppleScript-Editor open insert append toc
property myName : "_keychain"

General

getLoginAndPasswordForKey(keyName, keychainName)

Get the login (access) name and the password of a key stored in a Mac OS keychain.

keyNamestringname of the key in the keychain
keychainNamestringname of the keychain
listlist containing login and password

Written by:ljr

Example:

getLoginAndPasswordForKey("Ebay", "login") 
--> {"myEbayName","EbayPassword"}
show source AppleScript Editor open insert append toc
on getLoginAndPasswordForKey(keyName, keychainName)
	local keyName, keychainName, thisKey, thisChain
	local thisAccount, thisPassword
	try
		-- correct German name of login keychain
		-- add more languages if necessary!
		if keychainName starts with "Anmeldung." or ¬
			keychainName is "Anmeldung" then
			set keychainName to "login.keychain"
		end if
		-- add '.keychain' if missing
		if keychainName does not end with ".keychain" then
			set keychainName to keychainName & ".keychain"
		end if
		-- get account and password
		tell application "Keychain Scripting"
			set thisChain to keychain keychainName
			set thisKey to first key of thisChain whose name is keyName
			set thisAccount to thisKey's account
			set thisPassword to thisKey's password
		end tell
		return {thisAccount, thisPassword}
	on error eMsg number eNum
		error "Can't getLoginAndPasswordForKey: " & eMsg number eNum
	end try
end getLoginAndPasswordForKey

Copyright

© 2008 ljr (http://applescript.bratis-lover.net)
getLoginAndPasswordForKey

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.