Exporting Addresses

Posted:
in Genius Bar edited January 2014
Does anyone know a way to export the addresses from the address book to a cvs?



Thanks in advance

Comments

  • Reply 1 of 6
    Quote:

    Originally posted by sroach

    Does anyone know a way to export the addresses from the address book to a cvs?



    Thanks in advance




    Well, this should be possible with AppleScript. I'll have a look into this... will post a code example later on - or mail me, if you've got further questions.



    Greetings!

    durandal
  • Reply 2 of 6
    Well, here's the example. WARNING: This is really a Quick-Hack, w/o any error-catching routines and far from being suitable for real-world usage. But I think it gives the general idea on how to do the Address Book -> CSV thing.



    Explanation: The "tell application" Block creates a list, containing the name, street, city and zip code of the first person in the address book. The following statements allow the user to specify a new file name. That file is created and the list is written to it, with the values separated by commas.



    Questions? Post 'em here or mail me...



    Greetings!

    durandal



    Code:


    tell application "Address Book"

    set address_list to {name of person 1, street of address of person 1, city of address of person 1, zip of address of person 1}

    end tell



    open for access (choose file name) with write permission

    set FilRef to (result)

    write (item 1 of address_list) & "," & (item 2 of address_list) & "," & (item 3 of address_list) & "," & (item 4 of address_list) & (return) to FilRef

    close access FilRef



  • Reply 3 of 6
    sroachsroach Posts: 105member
    Durandal,



    I sent you an e-mail. Thanks for taking a crack at this for me. I am only getting 1 contact in the input file and it's a name with comma's after it.





    NAME, , ,
  • Reply 4 of 6
    Quote:

    Originally posted by sroach

    Durandal,



    I sent you an e-mail. Thanks for taking a crack at this for me. I am only getting 1 contact in the input file and it's a name with comma's after it.





    NAME, , ,




    Hmm.. okay. About getting only one contact: As I stated above, this is just an example. The script isn't supposed to export more than one contact (I just wanted to show how to write a contact to a CSV file). Re-writing it to handle all contacts in the Address Book shouldn't be too hard.



    The other error (NAME, , , ) - well 't was pretty late when I hacked that example, sorry

    I'm a bit short of time right now, will be back tonight and then I'll try to fix the prob.



    Greetings,

    durandal
  • Reply 5 of 6
    sroachsroach Posts: 105member
    Again than you for any time you put in to it.
  • Reply 6 of 6
    I modified the script code a bit (you may download the script from http://www.advancedscripting.de/sroach/a_export.hqx). Worked fine in Panther (can't test in Jaguar right now, since it currently isn't installed on my Mac, sorry).



    Greetings!

    durandal



    P.S.: The fact that the script now takes the second person (person 2) doesn't have any special meaning.



    Here's the code:



    Code:


    tell application "Address Book"



    set address_list to {name of person 2, street of address of person 2, city of address of person 2, zip of address of person 2}



    open for access (choose file name) with write permission

    set filref to (result)

    write ((item 1 of address_list) as text) & "," & ((item 2 of address_list) as text) & "," & ((item 3 of address_list) as text) & "," & ((item 4 of address_list) as text) & (return) to filref starting at ((get eof filref) + 1)

    close access filref



    end tell



Sign In or Register to comment.