Sub topic 11
Moving contacts with vCard files
This chapter assumes you can open the Contacts app, you know what a contact card is, and you have at least one account set up in System Settings. You will learn what a vCard file contains, how to export and import cards on a Mac, and what goes wrong when you do.
What a vCard file is
A vCard is a plain text file, usually with the extension .vcf. It describes one person or organization. A single .vcf file can hold one card or many cards, one after another. Almost every contacts program can read vCard files, including Contacts on macOS, iOS, Android, Outlook, and Gmail. That makes it the common format for moving people between systems that do not share an account.
Each card starts with BEGIN:VCARD and ends with END:VCARD. Between those lines, each property sits on its own line as a name, an optional set of parameters, a colon, and a value.
BEGIN:VCARD
VERSION:3.0
FN:Ada Example
N:Example;Ada;;;
EMAIL;TYPE=INTERNET:[email protected]
TEL;TYPE=CELL:+1-555-0100
END:VCARDThe properties in this card are:
| Line | Meaning |
|---|---|
| `VERSION:3.0` | The vCard format version. Versions 3.0 and 4.0 are common. |
| `FN` | The formatted name, which is the full name shown for the card. |
| `N` | The structured name: family name; given name; additional names; prefix; suffix. |
| `EMAIL;TYPE=INTERNET` | An email address. The `TYPE` parameter labels it. |
| `TEL;TYPE=CELL` | A phone number labeled as a mobile number. |
You can save this text in a plain text editor as ada.vcf and import it. Make sure the editor saves plain text and does not add a .txt extension.
When to use vCard files
You do not need vCard files to keep contacts in step between devices. An iCloud, Exchange, or CardDAV account does that automatically, as the iCloud sync chapter describes. Use vCard files when:
- You send one person's details to someone by email or message.
- You move contacts between accounts, for example from an old IMAP-only setup into iCloud.
- You move contacts to or from a program or service that has no shared account with your Mac.
- You want a backup of your contacts that you can read without Contacts.
Exporting contacts
There are two export commands in Contacts, and they differ.
- Export vCard. Select one or more cards, or a group, and choose File > Export > Export vCard. You get a
.vcffile. Selecting several cards produces a single file that contains all of them. - Contacts Archive. File > Export > Contacts Archive saves your whole Contacts database as a
.abbupackage. It is a backup that only Contacts can restore. It is not a vCard.
To export everything as vCard, click the account or All Contacts in the sidebar, press Command-A to select all cards, and then use Export vCard. To export one group, select the group in the sidebar and use the same command. The result contains the cards in that group only.
You can also drag a card from Contacts to the Desktop or into a Finder window. Contacts writes a .vcf file for it. Dragging a card into a Mail message attaches it as a .vcf file.
Importing contacts
You can import in three ways:
- Choose File > Import in Contacts and pick a
.vcffile. - Drag a
.vcffile from Finder onto the Contacts window. - Double-click a
.vcffile in Finder. Contacts opens and asks you to confirm the import.
When the file holds one card, Contacts may open it for review first. When the file holds several cards, Contacts asks whether to import them all.
Which account receives the cards
Imported cards go to the account that is the default for new contacts. You set this in Contacts > Settings > General, under Default Account. If the default is iCloud, imported cards appear on your other devices shortly after. If the default is On My Mac, they stay on this Mac.
Check this setting before a large import. Cards put in the wrong account are tedious to move. You can drag cards from one account to another in the sidebar, but you must select them first and the sidebar must show the accounts, which it does when you have more than one.
Duplicates
If an imported card matches an existing one, Contacts asks what to do. The choices are usually to review the duplicates, to skip them, or to import them anyway. Contacts decides on a match mostly from name and other details.
The Card menu has Look for Duplicates. Use it after an import. It finds cards that look like the same person and offers to merge them. Merging combines the fields into one card. Read the list before you accept, because two people with the same name will also appear there.
What can go wrong
| Problem | Likely cause | What to do |
|---|---|---|
| Accented letters appear as garbage | The file was saved in a text encoding other than UTF-8 | Re-export from the source as UTF-8, or re-save the file as UTF-8 in a text editor |
| Only the first card imports | A hand-edited file is missing an `END:VCARD` or a `BEGIN:VCARD` line | Open the file, and check that every card has both lines |
| Photos are missing | The source program did not embed photos in the vCard | Export again with a setting that includes photos, if the source has one |
| Fields land under the wrong label | The source used custom labels that Contacts does not recognize | Edit the card after import |
| Groups are lost | The vCard format has no standard way to store group membership in Contacts | Recreate the groups, or export each group on its own |
| Cards go to the wrong account | The Default Account setting pointed elsewhere | Move the cards in the sidebar, then change the setting |
The group problem matters when you move a whole address book. A file exported from All Contacts holds the people but does not reliably carry the groups. Export each group on its own, name the files after the groups, and rebuild the groups by importing each file into a new group.
How the pieces connect
Checking and handing off from the shell
A .vcf file is text, so the shell can inspect it. This counts the cards in a file:
grep -c "^BEGIN:VCARD" ~/Desktop/contacts.vcfIf the number differs from what you expected, a card is damaged or missing. You can also open a file with Contacts from Terminal:
open -a Contacts ~/Desktop/ada.vcfThis does the same as double-clicking the file, so Contacts still asks you to confirm the import.
You can list the groups Contacts holds with AppleScript before and after an import, to check that nothing changed that you did not intend:
tell application "Contacts"
get name of every group
end tellThe first time a script or Terminal asks Contacts for data, macOS may ask for permission. That is controlled in Privacy & Security, which a later chapter covers.
Privacy when you share a card
A card you export or send contains every field on it. That includes notes, birthdays, and addresses. Open the card and check the fields before you send it. Some versions of Contacts offer a choice in the share sheet, or in Settings, about which fields to include. If a card holds a note you wrote for yourself, remove it from the card or delete it before you export.
Exercise
You export All Contacts as one vCard file, import it into a new Mac, and find that every person is there but your groups are gone. Why, and how would you avoid it next time?
Show answer
A vCard file stores people, and Contacts does not reliably store group membership in it. To keep groups, export each group on its own (select the group in the sidebar, then File > Export > Export vCard), name each file after its group, and on the new Mac create the groups and import each file into its group. For a backup that restores everything, including groups, also make a Contacts Archive with File > Export > Contacts Archive.
Exercise
A file holds 40 cards, but only the first one imports. You open it in a text editor. What do you check, and what Terminal command gives you the card count?
Show answer
Check that each card starts with BEGIN:VCARD and ends with END:VCARD, because a missing line can stop the import after the first card. Count the cards with grep -c "^BEGIN:VCARD" file.vcf and compare the result with 40.