Better multi-country support in Contacts | Winfred van Kuijk

Better multi-country support in Contacts

By • Published: January 4, 2010 • Last updated: June 4, 2023 • Filed in: Software

Share
Here is a free plug-in that I have written for Apple’s Contacts (Address Book) that provides better multi-country support:

  • country names: you no longer have many variations for country names (so: all “United States”, instead of many variations like “USA”, “US”, “United States of America”);
  • country address formats: it tells Contacts to use the formatting that belongs to that country (e.g. my default format is for the Netherlands, which normally means for US addresses that state is missing and zip and city are switched).

Before (left): non-standard country name and incorrect format (state is missing, zip and city are switched)
After (right): standard country name and correct format

Quite useful for those that have contacts in multiple countries. You can specify in the script what countries to check and what your preferred country names are. Missing/unknown countries are added as a group in Contacts.

Simply download and run, or install as plug-in in /Library/Address Book Plug-Ins ~/Library/Application scripts/com.apple.AddressBook (location appears to have changed in 10.9.2.

September 2014: v1.9 introduces progress meter (available in Yosemite), user request added (only process contacts in defined group), bug fixes.


Standard country names

Before I had the script, I had many variations of country names (“United States”, “United States of America”, “USA”, “US”, etc.). For filtering and searching it would be nice to have a standard country name. The script looks for -defined by you- country name aliases and replaces them by the -defined by you- preferred name.

Related, request for Apple: please add filtering for country. I can filter (smart group) based on city, state or zip… but not country. In the mean time I use the generic address filter when I want to create a smart group.

Country address formats

It took me a while to discover the -built in- support for address formats. While in Edit mode, you can click on the address label (e.g. work/home) and then select the Change Address Format. What this does is setting the Country Code field, which is the iso code for that country. Not only is this setting difficult to find, it is a pain to do it if you have many international cards. Plus: if the country is already known, why would you have to do this at all?

This is where the script helps. When you run it, it will look for the regular country field and if it is one of the recognized names then it will set the country code.

Here are a couple of examples of the different country formats (click to enlarge):

Default country format

In the settings you can define your default country format:

Download the script

Download “AppleScript - fix country names and formats in Contacts”

contacts country names and codes.zip – 85.12 KB
before updating, first copy settings + the country table.

Revision history:
v1.0, 2010/01/03, initial release
v1.1, 2010/01/04, added result display options, added ability to run as Address Book plugin, Growl support
v1.2, 2010/01/10, added support for all known iso countries, write results to log file for easy copy/paste
v1.2.1, 2010/01/11, small Growl fix for non-Growl users
v1.2.2, 2010/01/12, leave iso code empty in lookup list to overwrite Apple’s format + check small countries if not in large country list
v1.3, 2010/01/12, added support for optional checking of latest version of plug-in
v1.4, 2010/01/15, added support for groups: adds missing/unknown country entries, extra check for problematic cards
v1.5, 2010/02/06, using “iPhone” country list instead of official ISO list, changed default values of some parameters
v1.5.1, 2011/07/28, small fixes, Lion compatibility, changed default values of some parameters
v1.5.2, 2011/08/20, small fixes, growl fix, user request: made preferred country case sensitive
v1.6, 2013/03/31, renamed script, fixed country code for Japan and Czech Republic, speed improvement for searching countries,
fix for read-only accounts (e.g. Facebook), removed Growl to improve Mac OSX compatibility, use optional notification center script, quick install in Terminal: sudo gem install terminal-notifier
v1.7, 2013/10/26, compatibility with Mavericks, use native notifications (10.9 or higher), improved detection of read-only accounts (Facebook etc.)
v1.8, 2014/01/13, user suggestion: create summary of countries per country code
v 1.9, 2014/09/01, Yosemite progress support, user suggestion: only check contacts in a specific group (property check_only_contacts_in_group), bug fixes

How to install & run the script

After downloading the .zip file, double click to unzip. You will now have the Applescript script.
There are two options to run the script:

  • plug-in for Contacts (preferred): install the script in [user home]/Library/Address Book Plug-Ins [user home]/Library/Application scripts/com.apple.AddressBook (per user) or /Library/Address Book Plug-Ins /Library/Application scripts/com.apple.AddressBook (all users). Note: the location has changed since 10.9.2. To use: select an address label (work/home/etc.) and click on “Check all country names and codes”.
  • standalone: save the script anywhere and double-click to open in Apple’s Script Editor. Optionally you can uncomment the log lines to get a detailed log of the actions.

For both (optional): open the script in AppleScript Editor and customize the sections between #### … #### (see customize section). Restart Contacts if you make changes to the settings or table. Run the script as often as you like.

Feedback

By default (as of version 1.4), you will get feedback in Contacts itself. Two groups will automatically be created and filled with people:

  • that have an address in an unknown country (note that “unknown” can also mean: not in your country table);
  • that have an address, but where the country field is empty.

Note that this is an *add-only* action (and not a “smart group”), it is up to you to clean/remove the groups when you have modified the records.

If you want, you can get a summary at the end (by setting the optional parameter show_results). A summary will be placed on your Desktop and opened in TextEdit.

The unknown country section is ready for copy&paste to the script. Go through the list, modify it the way you like and make sure no “??” iso codes remain.
The missing countries section is FYI, you can update those addresses if you want to. It is the same names that appear in the “without country group”.

Performance

The performance depends on the size of your Contacts database and how clean the data is.
E.g. for me it took 81 seconds the first time (656 people checked, 81 country names updated, 480 country formats updated), now it takes about 4 seconds.

Test vcards

If you want to test the script before you let it check all your address book cards, enable the setting in the script and create entries in Address Book with last name “testing”. Instead of creating them yourself, you can also download the test cards I have used.

[Download not found]

After testing, you can disable the setting again and delete the cards from your Address Book.

Customize the script

It is up to you to tell the script what country names to look out for.
The structure: iso code, list of preferred name and -if you want- aliases for that country. The bottom of the script has a list of all of the iso country codes and names, in the list at the top you tell it what you want it to look like. Different language, add alternative names/languages, etc. Is the standard entry in the iso list ok with you? Then there is no need to add it to the top list (although, if you do: it will speed up the script).

Note: only use the iso codes from the bottom list of the script, these are the ones that Apple recognizes. Any unknown iso codes will result in Contacts hiding that address (even though the iso code is legal, e.g. “AN” for “Netherlands Antilles”).

This is what the list could look like:

copy {"nl", {"Netherlands", "Nederland", "the Netherlands", "NL"}} to end of clist
copy {"be", {"Belgium", "België", "Belgique"}} to end of clist -- use the English name
copy {"de", {"Deutschland", "Germany"}} to end of clist -- use the German name
copy {"gb", {"United Kingdom", "UK"}} to end of clist
copy {"us", {"United States", "USA", "US", "United States of America"}} to end of clist
copy {"fr", {"France"}} to end of clist -- example of country with no aliases
copy {"ve", {"Venezuela"}} to end of clist -- example of overwriting name from iso list
copy {"", {"Chile"}} to end of clist -- use "default country" format instead of Apple's format
--copy {"??", {"Luxembourg"}} to end of clist -- incorrect, iso code is missing
--copy {"an", {"Netherlands Antilles"}} to end of clist -- incorrect, Apple does not know this iso code
-- add as many lines as you like...

In the script you can set various parameters, the main ones:

  • add_to_groups: (default: true) create groups for entries with missing/unknown countries; is *add-only*, so clean up manually
  • show_results: (default: true) give feedback afterwards -see below-, shows contacts where country field is empty, and countries that are not in your table.

Your own language

Here is a quick example to show how you can set the language.

The first example will look for “Germany” in German and French and use the English version of the country name.

copy {"de", {"Germany", "Deutschland", "Allemagne"}} to end of clist

You prefer the German version? Simply make that the first name in the list entry. It will look for all entries “Germany” and “Allemagne” in your Contacts and replace them with “Deutschland”.

copy {"de", {"Deutschland", "Germany", "Allemagne"}} to end of clis

You don’t like the format that Apple picks for your iso code? Just pick another iso code or leave the field empty (it will then use your default country format).

68 Responses to “Better multi-country support in Contacts”

  1. John Graybeal says:

    Nice tool. But I am confused by something basic here. If I understand your work correctly, the country code does several things: (1) Indicates the country of the address for that contact. (2) Tells iphone (and others?) what the telephonic country code is. (3) Tells Address Book how to format this entry (or if empty, tells Address Book to use the default format).

    Do I understand this correctly? So if I want to not show a country in my Address Book contact displays, I have to reset all the country codes to “”? Seems like poor separation of content and view. What am I missing?

    • winfred says:

      Hi John, There are 3 items: a) the phone country code (e.g. +31-…), b) the country name field, c) the “hidden” field: country code. And: all three are unrelated. By setting the country code (c), address book is told what the displayed format is of the address (e.g. changing the display order of zipcode and city). Hope this helps.

  2. Reginald W says:

    Found this on MacOSX Hints and just wanted to let you know that your 1.4 script seems to work on Tiger (10.4.11) running on an iBook G4. The OSX Hints web site said it was only for 10.6 and 10.5. Place it into the Library/… instead of into the user setting.

    Being anal-retentive or ADD or something like that, I did put your list into iso code order to make it easier to find/edit an entry, added the “Allemagne” to Germany as in your example but that wasn’t in the script, preferred Germany over Deutschland and added Canada to the list as follows:

    copy {“be”, {“Belgium”, “België”, “Belgique”}} to end of clist — I like to use the English name for this country
    copy {“ca”, {“Canada”, “canada”, “Kanada”, “Kanata”}} to end of clist
    copy {“de”, {“Germany”, “Deutschland”, “Allemagne”}} to end of clist
    copy {“fr”, {“France”}} to end of clist — example of country with no aliases, only needed if not loading iso list
    copy {“gb”, {“United Kingdom”, “UK”}} to end of clist
    copy {“nl”, {“Netherlands”, “Nederland”, “the Netherlands”, “NL”}} to end of clist
    copy {“us”, {“United States”, “USA”, “US”, “United States of America”, “Estados Unidos”}} to end of clist
    copy {“ve”, {“Venezuela”}} to end of clist — example of overwriting the standard name from the iso list
    copy {“”, {“Chile”}} to end of clist — example: I don’t like Apple’s Chile format, leave iso code empty for default country format

    However, if I have “canada” in all lower case as the country name in the address book, the script does NOT change it to “Canada”, converting the lowercase “c” to “C”. Perhaps it works in Leopard/Snow Leopard, but not in Tiger, at least for me. Very minor point, not sure if it is anything worth fixing or not, just thought that I would point it out.

    I would suggest adding the comment in the instructions that if someone who is entering in country names always enters in a name that is always misspelled, just add the misspelling as an alias to let it correct it automatically instead of bringing it up to be corrected manually. As this would apply for the one misspelling it, it wouldn’t do to have it as an example, but simply as guidance. You mention about misspelling in your .PNG file above, but not in the 1.4 script except in the section on writing to the log file. Having it in your instructions section would make it more easily explainable.

    — you only need to add countries here if you want to a) use a non-iso name and/or b) if you want to add aliases and/or c) someone
    — is always misspelling a country name and you want to auto-correct it.
    — the iso names can be found at the bottom of the script

    The only other thing would be standardizing for province/state names or abbreviations in the same way as you are doing for country names, but more work for someone who knows scripting. I would ASSume that it would be a lot more difficult as it would require looking at the country name and then a list of province/state names that go with that country. For Canada, US and Mexico, the province/state name abbreviations WERE unique until Newfoundland changed from NF to NL and conflicted with one of the Mexican state abbreviations. Just a thought, not a request, but I’m sure people wouldn’t turn it down if implemented, but I would guess this would be a LOT of work to do.

    Thanks for this. First script for Address Book that I’ve put in. Actually, I think it is the first script I’ve put in period. I’m not a programmer and I’ve never gotten into scripting, Applescripting or other such things, although I’ve thought of trying to learn more about it. Going to have to look further into this though since your example worked so well. Take care.

    • winfred says:

      Hi Reginald, I have the feeling Twitter is not your thing, that limit of 140 characters would never work for you. 😉
      – lower/upper case: will think about it, for searching it is actually nice that it is case insensitive (find both “allemagne” and “Allemagne”);
      – will modify the comment according to your suggestion, thx;
      – province/state: that is beyond the scope 🙂

      • Reginald W says:

        I’ve heard that before! LOL! Verbose does not mean “my stereo”. LOL

        I’d rather be complete and long than short and the person I’m sending to not having a clue as to what I’m saying, or having to ask a zillion questions for them to know exactly what I meant. Thanks again for the script.

  3. Egidius says:

    Goedemorgen Winfred, ik krijg elke keer als ik probeer het script te installeren de mededeling dat ik eerst mijn settings moet updaten. Maar van wat en waar? Of heb ik iets over het hoofd gezien? Eerst wilde hij ook nog Growl-helper hebben plus de vraag om de settings te updaten, maar na installatie van Growl krijg ik alleen deze mededeling. Wat doe ik fout?

    Groet en dank, Hans

    • winfred says:

      De installatiestappen van de plug-in: open het script met AppleScript Editor de stukken aan tussen ###…###. Met name: de landen tabel en de variabelen. Pas als “I_am_ready” op true gezet is kan het script gebruikt worden. Er is een ingebouwde lijst van (Engelse) landennamen, wil je Nederlandstalige landnamen, zet deze dan in de tabel in het script. Voor Engelse uitleg, zie de “How to install & run the script” en “Customize the script” secties op de webpagina.
      Voor Growl, mijn script kijkt of Growl draait en maakt er gebruik van als dat het geval is. Van de Growl-helper is mij niets bekend, kan het zijn dat een oude versie van Growl dit zelf oproept?

      Nog meer vragen, stuur gerust een mail via het contact formulier.
      -Winfred

  4. […] delas é o suporte a múltiplos países. Graças ao desenvolvedor Winfred van Kuijk, porém, agora temos à disposição um plugin que promete resolver isso. Veja um rápido exemplo do que ele […]

  5. B says:

    Sorry, just disregard my question above. Obviously I just have to drag and drop the changed entries to the Exchange address book and they get updated there.

    Thanks again for this!

  6. B says:

    Hi Winfred, this seems to be a very useful script. I just tested it with your testing entries. However, I am running 10.6.2 and use Address Book exclusively with Exchange (no local addresses “On My Mac”. When running your script, it copied the testing entries to my local address book and changed them (correctly) there. But the entries on my Exchange address book remain unchanged. Any idea how I can use your script to change the entries on the Exchange server?

    Thanks!

  7. Q says:

    Brilliant idea to output the missing countries.

    • winfred says:

      In that case: you will like v1.4, these missing (and unknown) countries are added to Address Book groups. Available now, enjoy.

  8. Daniel says:

    This doesn’t work for me… I can do a single entry, but as soon as I reset the script to process all address book contacts, growl informs me that the script has started, then nothing, not even after half an hour (and there are only 458 cards in my address book). Sometimes, though not always, the Text Edit application launches, but it doesn’t come to the foreground by itself and the window is empty. Incidentally, when I process a single entry, the summary at the end is displayed in Growl, not in TextEdit. Any suggestions? I’m running 10.6.2 on an early 2008 Mac Pro Intel Xeon (2 quad-core Intel Xeons).
    Thanks,
    Daniel

    • Daniel says:

      SInce Winfred handles comments like the one I posted above off-line, it may appear to the casual browser that he does not react to issues reported on this page. Nothing could be further from the truth! After I reported my problem, I received an almost instant email reply, and after several more emails had been exchanged, my problem is now completely solved. In fact, I just sent the author the following email a few seconds ago:

      OK, Winfred, I think everything is cool now. I picked up a version of my address book from the day before I ran the script for the first time; I then downloaded and ran the latest version. Everything went perfectly well; the two groups in the address book were really created and contained entries that should really have been there. OK, I thought, now I simply have to manually updated my 9 problem contacts. Wrong! They had all been handled by the updated scripts already.

      I guess it is safe to say that version 1.4 now works perfectly well for me. Thank you so much for not only providing a valuable tool but for also taking the time to troubleshoot my individual problem. Isn’t it amazing that those who provide free services to the community also provide the best support? Great job!

      Vriendelijke groeten,

      Daniel

  9. Bobbi Style says:

    I had installed the script yesterday into Address Book on Snow Leopard 10.6.2 and it crashed immediately. Winfred got hold of me and we went back and forth trying different solutions. It turns out that the crash was caused by two versions of BTGoogleEarth trying to run at the same time. With Winfred’s help I managed to remove all traces of it and do a clean install which fixed the crashing issue completely.

    I must say a HUGE thanks to Winfred on emailing back and forth until this was fixed when it wasn’t even caused by Winfred’s script!
    Your little script was a massive upgrade to my Address Book Winfred!
    Carry on the good work 🙂
    Bobs

  10. Jeff Byrnes says:

    Too cool! Thanks for such a useful script.

  11. László says:

    Hi,
    your script migh come handy, as I share my time (and friends) between Hungary and the US. However, I cannot get over the “First check the settings” warning/error. Whatever I do, and however many times I restart Address Book, I cannot get over this. What should I do?

    Thanks.

    • winfred says:

      Before you can run the script, you need to open the script, modify the country list and set the I_am_ready parameter to true. This is needed because every country and even every person has his favorite names for countries. Hope this helps!

  12. Alex says:

    This is perfect! Thanks!

  13. King Kong says:

    Hi
    it does not work without Growl as far as I can tell. I modified it and then ran it and got a Growl error as a standalone app.
    Growl HelperApp not found.

    I do not use growl and do not want to use growl.

    Regards
    kay

  14. Pablo Toledo says:

    One question: you can change the format assigned by country? In the case of Chile, is simply wrong!

    • winfred says:

      That’s beyond my powers I am afraid. 😉 That is hard-coded by Apple.

    • Emlyn says:

      You could try to find another country that has the correct format for Chile, and use that ISO code.
      Or report the bug to Apple…

    • winfred says:

      Good suggestion. I have also made a quick update (v1.2.2), you can now also leave the country code field empty, it will then pick the default country format. Or as you wrote: use another country code.

  15. winfred says:

    I just uploaded v1.2 and incorporated feedback from the OneMoreThing.nl forum: a better description of how to customize the country table. Enjoy!

Leave a Reply

« | Home | »