Solved

Objective C Mac Phonebook to CSV

Posted on 2012-04-10
4
47 Views
Last Modified: 2016-06-07
I am searching for code in Objective C to convert the Mac Address book to a CSV file.   I wrote code in Applescript but I would like to convert this code to objective c so I can compile it.
0
Comment
Question by:fhazan001
4 Comments
 
LVL 24

Assisted Solution

by:fridom
fridom earned 500 total points
ID: 37841588
0
 

Accepted Solution

by:
fhazan001 earned 0 total points
ID: 37843102
Yes but I have never written any objective c so I am not sure where to start.  Even if I had a simple program that simply created a list of all the contacts with their email address's.   I could then extrapolate what to do.    Here is a simple AppleScript.   I just would like to see what this looks like in objective c to understand the concepts by example.

tell application "Address Book"
            -- init  lists
            set list_1 to every person
            set custom_email_types to {}
            set cc_rec to ""
            set cc to {}  
           
            repeat with person_rec in list_1
                repeat with this_email in email of person_rec
                    if (label of this_email is not in custom_email_types) then
                        set end of custom_email_types to label of this_email
                    end if
                end repeat
             end repeat
             
            --header
            set cc_rec to "\"" & "name" & "\""
            set cc_rec to cc_rec & ",\"" & "company" & "\""
            set cc_rec to cc_rec & ",\"" & "job_title" & "\""
            set cc_rec to cc_rec & ",\"" & "organization" & "\""
            repeat with this_email in custom_email_types
                set cc_rec to cc_rec & ",\"" & this_email & "\""
            end repeat
            copy cc_rec to the end of cc
           
            -- Detail
            repeat with person_rec in list_1
                set cc_rec to "\"" & name of person_rec & "\""
                set cc_rec to cc_rec & ",\"" & company of person_rec & "\""
                set cc_rec to cc_rec & ",\"" & job title of person_rec & "\""
                set cc_rec to cc_rec & ",\"" & organization of person_rec & "\""
                repeat with this_type in custom_email_types
                    set match_label to "false"
                    repeat with this_email in email of person_rec
                        if (label of this_email is in this_type) then
                            set cc_rec to cc_rec & ",\"" & value of this_email & "\""
                            set match_label to "true"
                            exit repeat
                        end if
                    end repeat
                    if match_label = "false" then
                        set cc_rec to cc_rec & ",\"" & "" & "\""
                    end if
                end repeat  
                                                           
                copy cc_rec to the end of cc
             end repeat  
               
             set the_file to ((path to desktop as text) & "addressbook.csv")
               
                try
                    set dataStream to open for access file the_file with write permission
                    set eof of dataStream to 0
                    repeat with the_text in cc
                        write the_text & return to dataStream starting at eof
                    end repeat
                    close access dataStream
                    on error
                    try
                        close access file the_file
                    end try
                end try
         
            end tell
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you other experts are anything like me you are always looking into and testing out new features. While I was doing some research one day I ran across an app that I installed on my Mac and used as a security system. Mac OS X: SecureHome uses your …
Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question