Solved

Objective C Mac Phonebook to CSV

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
Set up iPhone and iPad email signatures to always send in high-quality HTML with this step-by step guide.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

706 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now