Solved

Objective C Mac Phonebook to CSV

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

The /etc/authorization file in Mac OS X 10.x can be used to control access to the various panes of the System Preferences amongst other things. It’s used by some of us Mac Sys Admin’s to give Standard Users access to System Prefs panes that only adm…
There is a security feature on iOS devices that is nearly impenetrable when it has been activated.  This article will provide some possible solutions as well as necessary steps to take to ensure you do not end up with a locked device.
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 …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

895 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

14 Experts available now in Live!

Get 1:1 Help Now