Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

PC Outlook to Address Book to XML and much more Apps
I spent a lot of time moving my contacts' info from Outlook on Windows to Address Book, and printing them out very nicely in PDF. I learned quite a few things in the process. If you're interested in

  • Exporting data out of Outlook in vcard format
  • Importing PC-based vcards into Apple's Address Book
  • Getting rid of duplicates in Address Book
  • Exporting from Address Book to XML
  • Converting from AppleScript's text encoding (MacRoman) to unicode UTF-8 (used for XML)
  • Installing FOP to process XML with XSLT stylesheets and enjoying the PDF formatting possibilities
  • Dealing with bugs in File Vault with AppleScript
  • Easily backing up a File Vault home directory
... then read on!

[robg adds: This hint, with all of the included code, was over 35,000 words in length (that's about 17 pages in a typical 12-point font). I have not tested it, and since it was submitted by an anonymous user without an email address, I could not contact the author to verify my edits. So there's a reasonably good chance I made an error or two while working with the text and code for this hint -- please let me know if you find something wrong, and I'll fix it ASAP.]

  1. Exporting data out of outlook in vCard format:
    Outlook does have a VBScript function to do so, but it is problematic. First, it misses a field I needed (other fax). Second, it is 2.0 format, and there are some fields Apple's Address Book would label unproperly (for instance, other address would become a work address). So I wrote my own VBScript [view source], tailor made for the fields I wanted to export, but very easily customisable.

    This produced one long text file with all my contacts in it (c:Update.vcf). If you wanted a different vCard to export different fields or label them otherwise, here is the trick. Make a fake contact in Address Book, give information for all the fields you're interested in; export as vCard, drag this vCard to Text Edit and study the format. Then modify the above code to respect this format.

  2. Importing PC vCards into Address Book:
    When transfered on a Mac, all the accented characters of Uptate.vcf looked funny. I didn't know yet about libconv (see below), so I just opened it with Dreamweaver (where it appeared OK), and copy / pasted to a Word document that I would then save as text only. Then a drag and drop to Address Book, which imported my 2600 contacts in seconds.

  3. Getting rid of duplicates:
    Address Book is capable of updating a contact when you give it a vCard of a contact it already knows. But the problem with putting all your vCards in a single text document is that Address Book does not update duplicates. So I wrote an AppleScript [view source] to export them all as individual vCards into the Desktop Folder "leon." I then deleted everything in Address Book and reimported the individual vCards. Duplicates were eliminated. Be sure to check "Export Notes" in the vCard tab of the preferences of Address Book.

  4. Exporting from Address Book to XML:
    Well, here again the AppleScript code I wrote [view source] suited the fields I used in Address Book, but you can customize it. XML export is pretty straightforward. The code will export every contact in a file called "contacts.xml" in the folder Macintosh HD -> Users -> Shared; change it as needed for your setup.

  5. Converting from MacRoman to Unicode UTF-8:
    Place contacts.xml (from above) on the Desktop, and run this shell command on the Desktop:
      iconv -f "macroman" -t "UTF-8" ~/Desktop/contacts.xml > ~/Desktop/contacts2.xml
  6. Installing FOP to process XML and stylesheets:
    I know nothing about Java. So here is what I did. I downloaded FOP from xml.apache.org>, decompressed it, opened it, and moved all the files present in the folder "LIB" to /Library -> Java -> Extensions. I did not know how to set the variable JAVA_HOME permanently, so I just opened FOP.sh and wrote in it JAVA_HOME="/Library/Java/Home". Now I can process my contacts with XSLT, using an XSLT stylesheet I wrote [view source] and used, as well as an example of contacts.xml. If you install FOP, here is the command to build a very nice PDF:
    /path_to_FOP/FOP/FOP.SH  -xsl /path_to_stylesheet/style.xsl \
      -xml ~/Desktop/contacts.xml -pdf ~/Desktop/contacts.pdf
    Here's a sample XML contact file:
    <?xml version="1.0"?>
    <dataroot>
      <Contacts>
        <Nom><![CDATA[NAME, Firstname]]></Nom>
        <Societe><![CDATA[society]]></Societe>
        <Telmobile1><![CDATA[mobile phone number]]></Telmobile1>
        <Adressebureau><![CDATA[work address]]></Adressebureau>
        <Telephonebureau><![CDATA[work phone]]></Telephonebureau>
        <Telephone2bureau><![CDATA[second work phone]]></Telephone2bureau>
        <Telecopiebureau><![CDATA[work fax]]></Telecopiebureau>
        <Adressedomicile><![CDATA[home address]]></Adressedomicile>
        <Telephonedomicile><![CDATA[home phone]]></Telephonedomicile>
        <Telephone2domicile><![CDATA[other home phone]]></Telephone2domicile>
        <Telecopiedomicile><![CDATA[home fax]]></Telecopiedomicile>
        <Adresseautre><![CDATA[other address]]></Adresseautre>
        <Telephoneautre><![CDATA[other phone]]></Telephoneautre>
        <Telecopieautre><![CDATA[other fax]]></Telecopieautre>
        <Adressedemessagerie><![CDATA[email address]]></Adressedemessagerie>
        <Notes><![CDATA[notes]]></Notes>
      </Contacts>
    </dataroot>
  7. Dealing with bugs in File Vault:
    I found AppleScript to be full of bugs when using File Vault. The solution was to never work with any file or folder that was in the protected home path (such as the Desktop). I rather used the folder /Users -> Shared/ to write contacts.xml.

  8. Backing up a File Vault directory:
    As has been said many times, file corruption can happen using File Vault. To be able to go back in time, I have added this script to system's cron to run on a daily basis (using Cronnix to do so):
     #!/bin/bash 
    dayofweek=`date "+%A"` destination="/Users/protected_directory_backup_$dayofweek.sparseimage" 
    cp /Users/.SHORT_USER_NAME/SHORT_USER_NAME.sparseimage $destination 
    Be sure to replace SHORT_USER_NAME with the short name of the protected home directory). If anything goes wrong with File Vault, you would be able to go back in time as far as seven days ago. To do so, you would need to log out of the protected account, log in to anouther account with administrative rights, and run a command such as the following:
    sudo mv  /Users/SHORT_USER_NAME.sparseimage /Users/SHORT_USER_NAME.sparseimage.damaged
    sudo mv /Users/protected_directory_backup_CHOOSE_YOUR_WEEKDAY.spareseimage /Users/SHORT_USER_NAME.sparseimage
    sudo chown SHORT_USER_NAME:SHORT_USER_NAME /Users/SHORT_USER_NAME.sparseimage
    
    •    
  • Currently 1.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[21,025 views]  

PC Outlook to Address Book to XML and much more | 9 comments | Create New Account
Click here to return to the 'PC Outlook to Address Book to XML and much more' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
PC Outlook to Address Book to XML and much more
Authored by: blalor on Sep 17, '04 10:53:07AM

So how do you use these VB scripts? Is whitespace significant? If so, the linked files won't work.



[ Reply to This | # ]
Link to FOP is incomplete + FOP Info
Authored by: the_webmaestro on Sep 17, '04 11:28:35AM
The link to Apache FOP is incomplete (although it gets you to the top level of the Apache XML Project of which FOP is a sub-project). Here's the correct link to the FOP Project:
 
  • http://xml.apache.org/fop/
     
  • And the FOP download link is:
     
  • http://xml.apache.org/fop/download.html
     
  • [OT] BTW, FOP is a great tool for converting XML files to PDF, RTF, PCL & PostScript, as well as sending it directly to the printer or as a print preview (AWT). Of course, like most open source projects, we're always looking for more help! DISCLAIMER: I am an Apache FOP committer

    ---
    Father of Jeremy Logan

    [ Reply to This | # ]

    PC Outlook to Address Book to XML and much more
    Authored by: Safar on Sep 17, '04 12:40:17PM

    Hi there !

    I am the original poster. I thought I had logged in when posting

    safar



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: shahnr on Sep 17, '04 01:43:33PM

    I used Outlook2Mac, from littlemachines.com. It's a bargain at $10, and for a novice like me, more time efficient.



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: Safar on Sep 17, '04 02:31:40PM

    i did also, but then i discovered the problems mentioned above about the way Oulook exports vcards



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: eduo on Sep 24, '04 05:35:13PM

    This is actually more of a MEGA-Hint. Could be made into a feature were several hints are combined into a MEGA-Hint (there is a lot of cross-referencing to other hints in several of them).

    I myself was hoping to use this as a basis to transfer my calendar from Outlook to my iCal machine, but couldn't do this easily.

    Hmm. To keep on looking.

    Eduo

    ---
    Eduo



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: Code Masseur on Jan 26, '05 08:13:29PM

    The script listed in step 1 ("pc_outlook_export.txt") has a couple issues which need to be corrected in order to be useful.

    1. The script can't handle items in the contacts folder which aren't individual contacts (such as a distribution list). The original submitter almost got this right, when he included this line:

    
    If objItem.Class = olContact Then
    

    Unfortunately, this check needs to be made before the line:

    
    Set objItem = objPress.Items.Item(intLoop)
    

    The way I solved this was by making the check:

    
            If objPress.Items.Item(intLoop).Class = olContact Then
    

    and that fixed the script errors which will be otherwise encountered.

    2. The output is in French. For English-speakers, "domicile" changes to "Home", "travail" changes to "Work" and "autre" changes to "Other".

    3. The default contacts folder is not exported. Instead a sub-folder called "presse archives" (Literal English translation: "Press Files"?) is exported. This is easily addressed by either creating a sub-folder which you copy your contacts into for export and updating the script with the proper name or by modifying the script, which I did.

    Critique aside, this was a very useful tool, and I thank the contributor for making it available. It saved me lots of headache as I have hundreds of contacts in Outlook which I wanted to export into the Mac OSX Address Book application.



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: wuhair on Jun 22, '07 08:29:27AM

    Do you know how to edit the code so that you can have:
    Job title
    Email address 1
    Email address 2
    Email address 3

    thanks,

    Winston



    [ Reply to This | # ]
    PC Outlook to Address Book to XML and much more
    Authored by: wuhair on Jun 22, '07 08:31:51AM

    Do you know how to edit the code so that you can have:
    Job title
    Email address 1
    Email address 2
    Email address 3
    Category

    thanks,

    Winston



    [ Reply to This | # ]