export-passwords.txt 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. set the logFile to ((path to desktop) as string) & "Passwords"
  2. set keychainPath to "/Users/andrewlewman/Desktop/my.keychain"
  3. -- write_to_file taken from http://www.macosxautomation.com/applescript/sbrt/sbrt-09.html
  4. on write_to_file(this_data, target_file, append_data)
  5. try
  6. set the target_file to the target_file as string
  7. set the open_target_file to open for access file target_file with write permission
  8. if append_data is false then set eof of the open_target_file to 0
  9. write this_data to the open_target_file starting at eof
  10. close access the open_target_file
  11. return true
  12. on error
  13. try
  14. close access file target_file
  15. end try
  16. return false
  17. end try
  18. end write_to_file
  19. tell application "Usable Keychain Scripting"
  20. set keychainItems to get every keychain item of keychain keychainPath
  21. repeat with keychainItem in keychainItems
  22. set aServer to server in keychainItem
  23. set anAccount to account in keychainItem
  24. set aPassword to password in keychainItem
  25. set csvEntry to aServer & "," & anAccount & "," & aPassword & "
  26. "
  27. my write_to_file(csvEntry, logFile, true)
  28. end repeat
  29. end tell