This python script reads an AddressBook database file (AddressBook-v22.abcddb) and export its content to a vCard file (.vcf).
I created this script to automate my contacts backup procedure. The output of this script should be exactly the same as dragging and dropping the "All Contacts" card.
To install abcddb2vcard from PyPi, use pip:
pip install abcddb2vcardabcddb2vcard can then be used from any working directory in the Terminal.
To uninstall:
pip uninstall abcddb2vcardExport all contacts
abcddb2vcard backup/contacts_$(date +"%Y-%m-%d").vcfExport into individual files
abcddb2vcard outdir -s 'path/%{fullname}.vcf'Extract contact images
vcard2img AllContacts.vcf ./profile_pics/usage: abcddb2vcard [-h] [-f] [--dry-run] [-i AddressBook.abcddb] [-s FORMAT]
outfile.vcf
Extract data from AddressBook database (.abcddb) to Contacts VCards file
(.vcf)
positional arguments:
outfile.vcf VCard output file.
optional arguments:
-h, --help show this help message and exit
-f, --force Overwrite existing output file.
--dry-run Do not write file(s), just print filenames.
-i AddressBook.abcddb, --input AddressBook.abcddb
Specify another abcddb input file. Default:
~/Library/Application Support/AddressBook/AddressBook-v22.abcddb
-s FORMAT, --split FORMAT
Output into several vcf files instead of a single
file. File format can use any field of type Record.
E.g. "%{id}_%{fullname}.vcf".
usage: vcard2img [-h] infile.vcf outdir
Extract all profile pictures from a Contacts VCards file (.vcf)
positional arguments:
infile.vcf VCard input file.
outdir Output directory.
optional arguments:
-h, --help show this help message and exit
firstnamelastnamemiddlenamenameprefixnamesuffixnicknamemaidennamephonetic_firstnamephonetic_middlenamephonetic_lastnamephonetic_organizationorganizationdepartmentjobtitlebirthday[email][phone][address][socialprofile]note[url][xmpp-service]imageiscompany
Currently, the image field only supports JPG images.
But as far as I see, Apple converts PNG to JPG before storing the image.
If you encounter a db which includes other image types, please let me know.
You should check the output for yourself before using it in a production environment. I have tested the script with many arbitrary fields, however there may be some edge cases missing. Feel free to create an issue for missing or wrong field values.
Note: The output of
difforFileMerge.appcan be different to this output. Apple uses some data transformations (on vcf export) which are not only unnecessary but may break the re-import of the file.