Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Objective C Mac Phonebook to CSV

Posted on 2012-04-10
4
50 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

The error "There was an error performing the update" occurred on a Mac OS X client workstation running  Symantec AntiVirus for Mac (http://www.symantec.com/business/products/purchasing.jsp?pcid=pcat_security&pvid=825_1) - the Enterprise product vers…
We could spend the next millennium discussing the differences of the Mac and Windows platforms. The next century will continue to have fanatics on both side of the equation and neither side will win the war. However, that’s not why we are here. W…
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…

856 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