Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

exporting keychain passwords

Hi,
I would like to export the passwords stored in my keychain file.
I need them in a clear readable format for moving them on my Iphone and a Windows netbook

Is it possible?

I read really a lot about exporting passwords from Keychain. It seems the following link solved the problem to some people: http://discussions.apple.com/thread.jspa?messageID=1163575&#1163575

The script did not work for me. It aborted after a while (I think just before writing the file with the passwords).

thanks all for the help you will give me!

MacBook Pro 15" Intel, Mac OS X (10.6.4)

Posted on Aug 21, 2010 4:26 AM

Reply
13 replies

Aug 21, 2010 11:19 AM in response to maxco

The script runs w/o issues on my machines, so I have no idea why it's not working on yours. Run it and provide error details and we should be able to sort things out for you. It does require that the Keychain Scripting.app be in /System/Library/ScriptingAdditions/.

Here's the script, so you don't have to go back.

<begin script>

+set osXKeychainScriptingPath to ¬+
+ (path to scripting additions from system domain as Unicode text) ¬+
+ "Keychain Scripting.app:" -- one line+
+set theSecuridPIN to {}+

+tell application "Keychain Scripting" to launch+
+tell application "Keychain Access" to launch+

+using terms from application "Keychain Scripting"+
+ tell application osXKeychainScriptingPath+
+ set KeyList to every Internet key of current keychain+
+ repeat with aKey in KeyList+
+ set theSecuridPIN to theSecuridPIN & ((name of aKey) & tab & ¬+
+ (account of aKey) & tab & (password of aKey) & return) as text+
+ end repeat+
+ end tell+
+end using terms from+

+tell application "Keychain Scripting" to quit+
+tell application "Keychain Access" to quit+

+tell application "Finder"+
+ open for access file (((path to desktop folder) as text) & "Passwords") with write permission+
+ set theFile to result+
+ write theSecuridPIN to theFile+
+ close access theFile+
+end tell+

<end script>

Aug 22, 2010 8:49 AM in response to maxco

Hi I changed the second line in order to introduce the required path as follows:

set osXKeychainScriptingPath to ¬
"/System/Library/ScriptingAdditions/Keychain Scripting.app" -- one line
set theSecuridPIN to {}

As a result when I run it I receive an error:
Keychain Scripting found an error tye 2378.

In the Editor, the 'password' term was highlighted in the following line when the error occurred:
(account of aKey) & tab & (password of aKey) & return) as text

What is really annoying of executing this code is that I need to manually confirm the access to all passwords. A windows shows per each and I need to grant access to the password twice per each website.
The messages I obtain are something like:
Applescript editor is trying to obtain the password for (website). …. (Always allow, Deny, Allow)
Keychain Scripting wants to use the information stored in (website) in your keychain (Always allow, Deny, Allow)


Ps: messages here reported are translation from Italian so may not be perfectly fitting the original English message.

What is wrong?
thanks

Aug 22, 2010 10:43 AM in response to maxco

Don't know why it's erroring on the path.
What is really annoying of executing this code is that I need to manually confirm the access to all passwords.

That's expected behavior as I explained in linked post;

+The first time through you'll have to click the Allow Always and/or Allow Once button for each username/password combo…+ Do note that I only click the right-hand button.

I've not found a way to automate that. However, since I only run it every three or four months, it's not much of an imposition.

Aug 22, 2010 11:54 AM in response to baltwo

no, as I said before the script aborted with error type 2378. Any suggestion is still welcome.

I was only hoping to find some time for studying the Apple Script language and eventually solve my problem (I understand it is not so easy for you without an access to the computer where the problem arises)

Message was edited by: maxco

Message was edited by: maxco

Aug 22, 2010 12:32 PM in response to maxco

Sorry, I thought the error was coming before you changed the path. From the MacErrors.h file, there's this:

+*Dialect-specific AppleScript errors:*+

+The range -2780 thru -2799 is reserved for dialect specific error codes for+
+scripting components that support dialects. (Note that error codes from+
+different scripting components in this range will overlap, as well as error+
+codes from different dialects in the same scripting component.)+

If possible, change your language to English and see if that error goes away. It might be a localization issue.

Aug 23, 2010 1:40 AM in response to baltwo

nothing...
changed the language to English from system preferences but I still got the error.
It is like the 'password' field is not in aKey
As I said, the error is in password keyword in the line:
(account of aKey) & tab & (password of aKey) & return) as text

An alternative way for addressing the 'password' field? Probably a good idea may be a script for printing the list of field names in aKey. Just to be sure the term 'password' is correct.

A simplified script for trying different solution more quickly? (without authorizing the access to 281 passwords 🙂 )

I will be away from my mac (sigh!) for a few days.
thanks again baltwo, this is taking you a lot of time, sorry for that.

Message was edited by: maxco

Aug 23, 2010 10:07 AM in response to maxco

If it errors on password of aKey, then I suspect that the login.keychain might have issues. Launch Keychain Access, select Keychain First Aid, and verify and repair the keychain. This script has worked for over five years and no one else has mentioned this kind of error. As I noted above, I just ran it with 10.6.4 w/o errors.

Sep 6, 2010 2:23 PM in response to baltwo

Hi,
it worked eventually!
Several issues were to be fixed:
1) There were some errors in the keychain (solved with the first aid utility, thanks for the suggestion)
2) the code could not access the support.apple.com password (very strange, isn't it?)

I solved issue 2 by introducing the line:
log theSecuridPIN

just before the 'end repeat'
Once I identified the password who gave the problem I removed the entire entry and it worked!

thank you very much for your great help

Sep 6, 2010 2:26 PM in response to Tirademan

AFAIK, you have to change *current keychain* to something like *keychain whose name is XXXX*. Check the dictionary for Keychain Scripting. Alternatively, remove the login.keychain file from your /Library/Keychains/ folder, rename this other one to login.keychain, restart, run the script, and then revert back.

exporting keychain passwords

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.