Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Objective C Mac Phonebook to CSV

Posted on 2012-04-10
4
Medium Priority
?
77 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
[X]
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
4 Comments
 
LVL 24

Assisted Solution

by:fridom
fridom earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Create a default user profile for Mac OS X 10.7/10.8 Create a user account on OS X that will be a template for every other user of that computer. I usually call it “profile” and make it an administrator account for the time being. 1. Install a…
A lot of new and distinct gadgets are making their appearance every other day. The latest gadget that has wooed the attention of all gadget lovers and non gadget lovers alike is the Smartwatch. This tiny gadget is capable of offering live access to …
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 …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

610 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