9 Replies Latest reply on Aug 12, 2014 4:45 PM by DanielChardon

    How to interface w/ Address Book?

    jprint

      Title

      How to interface w/ Address Book?

      Post

            

           I'm in the process of updating my contacts in my main FMP database.  I keep most of my everday contact on my Mac Address Book application - for phone numbers and emails (which is easier when working with my email client).  

           Can other forum members suggest the best / easiest way to interface FMP with Address book to make changes on BOTH ends?  

           Yes, I know there's an Address Book manipulator plug-in -- but it seems expensive and onerous to set up.  Some have suggested using Bento as a way to intervase between the Address Book and FMP, but I don't know if it can manage individual records.

           I'd welcome any suggestions...  Thanks! 

        • 1. Re: How to interface w/ Address Book?
          jprint

                

               Any ideas / suggestions...?

                

               Thanks!

          • 2. Re: How to interface w/ Address Book?
            jmw

                 You can also use AppleScript to access Address Book. I use it to interface to iCal reading and writing events to and from a database, so I would guess that interfacing to Address Book might be an option for you. 

            • 3. Re: How to interface w/ Address Book?
              jprint

                   Thanks so much!  I'm not pproficient with AppleScript...  Can you further advise me how to do this? Of course, a script would be eeven better -- if it's possible to furnish one...  Thanks so much  again...

              • 4. Re: How to interface w/ Address Book?
                jmw

                      

                     Firstly; google "applescript introduction" to get to grips with applescript. It will take a bit of time, but nothing too much, really, and it will be worth it. There are lots of excellent sites. For example http://mac.tutsplus.com/tutorials/automation/the-ultimate-beginners-guide-to-applescript-2/

                     Then; scripting address book in general: http://www.mactech.com/articles/mactech/Vol.21/21.10/ScriptingAddressBook/index.html  Use AppleScript Editor in the Utilities folder of your Applications folder to test the scripts, but before you do: make a backup of your current AddressBook!! 

                     As for example scripts for FileMaker: google "filemaker applescript address book" and you will get several sites explaining the interface and giving examples. Again, make a backup of your current AddressBook!! For example http://fmforums.com/forum/topic/45079-filemaker-to-os-x-address-book/  seems a nice starting point. 

                     These AppleScripts go in the FileMaker script-step "Perform AppleScript". The scripts mentioned above are put in the box "Native AppleScript", yet you can also create the using a calculation. Such a calculation must create a text with the correct script as a result. If you would like to use that method I suggest to create the calculation in a ordinary FileMaker variable (for example $ScriptText) and use that in the scriptstep calculation. This way you can inspect the variable in the debugger (or a test-textfield on your layout) to see if the script is what you want it to be. And... make a backup of your current AddressBook!! 

                     After that it depends on what it exactly is you want to do with regards to your database. I suggest making a few FileMaker test scripts to test simple things like changing the name either in or from the AddressBook, and go from there.

                     Good luck with it, and don't be afraid to ask if you get lost. smiley

                • 5. Re: How to interface w/ Address Book?
                  jprint

                       Thank you so much for all of your help, Jan...  I greatly appreciate it.  Unfortunately, the work involved in putting this together is too much for me to handle right now.  If there's a simplier solution or if you have any other ideas, please let me know...  Thanks again for all of your help!

                        

                       Best,

                        

                        

                       Josh

                  • 6. Re: How to interface w/ Address Book?
                    jmw

                         You're welcome. As an alternative; I stumbled upon a site the other day which has an AppleScript example and also mentions plugins to handle the interface: http://www.banks.id.au/filemaker/createcontactinaddressbook/

                         Maybe that is an easier option... 

                         Best of luck!

                         Jan Martin

                    • 7. Re: How to interface w/ Address Book?
                      jprint

                           Just want to thank you very much for all of your help with this (belatedly!)...

                            

                            

                      • 8. Re: How to interface w/ Address Book?
                        robcaldwell

                             Last month, I wrote an AppleScript to quickly export most of the Address Book data into a single .csv file.  It merges related data into single fields, like phone numbers and email addresses, so those will need a little adjustment once in FileMaker.  The script is still rough around the edges, but see if it helps get you started.

                              

                             

                                   

                             

                                  -- AppleScript exports multiple tables from OS X Address Book as single CSV table.

                             

                        settheExportPathto "~/Desktop/abook.csv"

                             

                        settheCommandPathto "~/Desktop/commands"

                             

                                   

                             

                        tellapplication "Finder"

                             

                        set os_version to version

                             

                        endtell

                             

                        ifos_version < 10.6 then

                             

                                  -- Snow Leopard (10.5) does not have group_concat function.

                             

                        display dialog "This version of the Mac OS X Address Book will not work with this script." buttons {"Cancel"}

                             

                        elseifos_version < 10.7 then

                             

                                  -- Address Book location for Snow Leopard (10.6)

                             

                        settheABPathto "~/Library/App*Sup*/Add*B*/Add*B*-v22.abcddb"

                             

                        else

                             

                                  -- Address Book location for Lion (10.7 & 10.8)

                             

                        settheABPathto "~/Library/App*Sup*/Add*B*/Sources/*-*/Add*B*-v22.abcddb"

                             

                        endif

                             

                                   

                             

                        settheUIDnumtodo shell script "sqlite3 " & theABPath & " 'select z_pk from zabcdCustomProperty where zabcdCustomProperty.zPropertyName=\"com.apple.uuid\" and zabcdCustomProperty.zRecordType=\"ABCDContact\";'"

                             

                                   

                             

                        do shell script "echo '.headers on' > " & theCommandPath --adds field names as first row

                             

                        do shell script "echo '.mode csv' >> " & theCommandPath --changes pipe delimited export to comma separated values

                             

                                   

                             

                        ifos_version < 10.7 then

                             

                                  -- Snow Leopard (10.6) does not have UID field values.

                             

                                   

                             

                        do shell script "echo 'select * , (select group_concat(zAddress||\"^\"||zLabel,\"Ω\") from zabcdEMAILADDRESS where theContact.z_pk=zabcdEMAILADDRESS.zowner) as ListEmails, (select group_concat(zAddress||\"^\"||zLabel||\"^\"||(select zServiceName from zabcdService JOIN zabcdMESSAGINGADDRESS ON zabcdService.z_pk=zabcdMESSAGINGADDRESS.zService),\"Ω\") from zabcdMESSAGINGADDRESS where theContact.z_pk=zabcdMESSAGINGADDRESS.zowner) as ListMessaging, (select group_concat(zFullNumber||\"^\"||zLabel,\"Ω\") from zabcdPHONENUMBER where theContact.z_pk=zabcdPHONENUMBER.zowner) as ListPhones, (select group_concat(zURL||\"^\"||zLabel,\"Ω\") from zabcdURLADDRESS where theContact.z_pk=zabcdURLADDRESS.zowner) as ListWebsites, (select group_concat(zDate||\"^\"||zLabel) from zabcdCONTACTDATE where theContact.z_pk=zabcdCONTACTDATE.zowner) as ListDates, (select group_concat(ifnull(replace(zStreet,\"

                             

                                  \",\"å\"),\"\")||\"^\"||ifnull(zCity,\"\")||\"^\"||ifnull(zState,\"\")||\"^\"||ifnull(zZipCode,\"\")||\"^\"||ifnull(zCountryName,\"\")||\"^\"||zLabel,\"Ω\") from zabcdPOSTALADDRESS where theContact.z_pk=zabcdPOSTALADDRESS.zowner) as ListAddresses, (select group_concat((select theGroup.zName from zabcdRecord theGroup where theGroup.z_pk=z_19ParentGroups.z_15ParentGroups1)) from z_19ParentGroups where theContact.z_pk=z_19ParentGroups.z_19Contacts) as ListGroups, (select zText from zabcdNOTE where theContact.zNote=zabcdNote.z_pk) as NoteText from zabcdRecord theContact;' >> " & theCommandPath

                             

                                   

                             

                        else

                             

                                   

                             

                        do shell script "echo 'select * , (select group_concat(zAddress||\"^\"||zLabel,\"Ω\") from zabcdEMAILADDRESS where theContact.z_pk=zabcdEMAILADDRESS.zowner) as ListEmails, (select group_concat(zAddress||\"^\"||zLabel||\"^\"||(select zServiceName from zabcdService JOIN zabcdMESSAGINGADDRESS ON zabcdService.z_pk=zabcdMESSAGINGADDRESS.zService),\"Ω\") from zabcdMESSAGINGADDRESS where theContact.z_pk=zabcdMESSAGINGADDRESS.zowner) as ListMessaging, (select group_concat(zFullNumber||\"^\"||zLabel,\"Ω\") from zabcdPHONENUMBER where theContact.z_pk=zabcdPHONENUMBER.zowner) as ListPhones, (select group_concat(zURL||\"^\"||zLabel,\"Ω\") from zabcdURLADDRESS where theContact.z_pk=zabcdURLADDRESS.zowner) as ListWebsites, (select group_concat(zDate||\"^\"||zLabel) from zabcdCONTACTDATE where theContact.z_pk=zabcdCONTACTDATE.zowner) as ListDates, (select group_concat(ifnull(replace(zStreet,\"

                             

                                  \",\"å\"),\"\")||\"^\"||ifnull(zCity,\"\")||\"^\"||ifnull(zState,\"\")||\"^\"||ifnull(zZipCode,\"\")||\"^\"||ifnull(zCountryName,\"\")||\"^\"||zLabel,\"Ω\") from zabcdPOSTALADDRESS where theContact.z_pk=zabcdPOSTALADDRESS.zowner) as ListAddresses, (select group_concat((select theGroup.zName from zabcdRecord theGroup where theGroup.z_pk=z_19ParentGroups.z_15ParentGroups1)) from z_19ParentGroups where theContact.z_pk=z_19ParentGroups.z_19Contacts) as ListGroups, (select group_concat(zStringValue) from zabcdCustomPropertyValue where theContact.z_pk=zabcdCustomPropertyValue.zowner and zabcdCustomPropertyValue.zCustomProperty=" & theUIDnum & ") as zUID, (select zText from zabcdNOTE where theContact.zNote=zabcdNote.z_pk) as NoteText from zabcdRecord theContact;' >> " & theCommandPath

                             

                                   

                             

                        endif

                             

                                   

                             

                        do shell script "sqlite3 " & theABPath & " > " & theExportPath & " < " & theCommandPath

                             

                                   

                             

                                   

                             

                                  (*

                             

                                  Data for the Address Book (Contacts) is scattered among several SQLite tables. This script tries to condense all the information into one flat table for easier management and incorporation into other solutions.

                             

                                  All of the SQLite3 commands are gathered into one 'commands' file, then executed by the last 'do shell script' line. Fields from related tables are joined into single fields for the export. Related records are separated by Omega (Ω), field values are separated by a carrot (^), and in-field returns are converted to an a with ring above (å). Group names are held in the zabcdRecord table, mixed in with the contact records, so to perform a self join I'm using 'theContact' and 'theGroup' as aliases for the zabcdRecord table.

                             

                                   

                             

                                  List of important SQLite tables in AddressBook-v22.abcddb (2013)

                             

                                  - zabcdRecord

                             

                                  - zabcdEmailAddress

                             

                                  - zabcdMessagingAddress

                             

                                  - zabcdPhoneNumber

                             

                                  - zabcdURLAddress

                             

                                  - zabcdContactDate

                             

                                  - zabcdPostalAddress

                             

                                  - zabcdNote

                             

                                  - zabcdCustomPropertyValue (contains UID or primary contact key for OS 10.7-10.8)

                             

                                  *)

                        • 9. Re: How to interface w/ Address Book?
                          DanielChardon

                                Great job Rob

                               just managed to export 4000 addresses into a filemaker database with your script, I am looking now for a solution ie automatic synchronisation betweeen mac address book and filemaker, not being able to create the necessary scripts, the address book manipulator which I just bought is asking for... see here: http://www.productivecomputing.com/address-book-integration

                               Thanks for your help anyway,

                               Daniel Chardon, Switzerland