Quickly extract all email addresses from Address Book
Aug 28, '08 07:30:02AM • Contributed by: Rainy Day

Aug 28, '08 07:30:02AM • Contributed by: Rainy Day
To quickly (as compared to using nested loops in AppleScript) extract all email addresses from the Address Book, you can tap into Address Book's SQLite database using the command line (in Terminal):
[robg adds: These commands worked as described when I tested them. If you cd to the directory first, of course, you can shorten the commands considerably, as you can leave out the full path, and just include the filename -- i.e. sqlite3 AddressBook-v22.abcddb "select ZADDRESS from ZABCDEMAILADDRESS;" | sort -f | uniq -i.]
sqlite3 ~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb "select ZADDRESSNORMALIZED from ZABCDEMAILADDRESS;"
If you want to alphabetize and remove duplicates:
sqlite3 ~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb "select ZADDRESSNORMALIZED from ZABCDEMAILADDRESS;" | sort | uniq
Please note: This works in Leopard, and should work in Tiger too. However, the database filename looks like it could change at any time (and may be different in Tiger). Also, the commands above "normalize" the email addresses (i.e. they convert all characters to lower case; this does not affect your ability to use them because eMail addresses are not case sensitive). If you do not want the email addresses normalized, substitute ZADDRESS for ZADDRESSNORMALIZED:
sqlite3 ~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb "select ZADDRESS from ZABCDEMAILADDRESS;"
If you want to alphabetize and remove duplicates, you need to add a few additional parameters to sort and uniq, so they will ignore case differences:
sqlite3 ~/Library/Application\ Support/AddressBook/AddressBook-v22.abcddb "select ZADDRESS from ZABCDEMAILADDRESS;" | sort -f | uniq -i
To save the output of any line above to a text file, append > /path/to/save/to/filename.txt to the command.
[robg adds: These commands worked as described when I tested them. If you cd to the directory first, of course, you can shorten the commands considerably, as you can leave out the full path, and just include the filename -- i.e. sqlite3 AddressBook-v22.abcddb "select ZADDRESS from ZABCDEMAILADDRESS;" | sort -f | uniq -i.]
•
[29,809 views]