1 2 3 Previous Next 37 Replies Latest reply: Aug 29, 2012 1:47 PM by hotwheels 22
hotwheels 22 Level 1 Level 1 (0 points)

i have been endlessly struggling with my various databases and i am not seeing what i think should be a natural integration between Mail Previous Recipients (Window > Previous Recipients) and a /folder/ in Mac Mail. right now this database resides /solely/ on one machine and i cannot get autocomplete for this data when writing emails on my other devices.

 

also, you cannot add these addresses in bulk (it will trash your database) and it appears to either over-write an existing phone number with a "new" same name contact with email address only or it create duplicate contacts (depending on whether you add them in bulk or add them individually).

 

ALSO, i am not exactly sure how you would MAINTAIN this database over time since if you manually enter the data into Contacts and then wipe the Previous Recipients clean - then ostensibly anytime you reply to an email address that already exists in a Contact database will get added to the previous recipients data in Mail and you will then have no way distinguishing between really new and new already existing email contacts.

 

so - can anyone code up a script that would let me simply add all the PREVIOUS RECIPIENTS data to a FOLDER in Contacts so that i can simply run it once in a while to update the data "port" to Contacts? if it resides simply in a folder named "previous recipients" this data will ostensibly be available to autocomplete on all my devices and it won't (i assume) clutter up or otherwise trash my existing Contacts database with all my phone numbers.

 

i have three or four hundred of these and while i can enter the data manually into my Contact database over time it would be a lot simpler to just have this data available in Contacts...

 

thank you for any consideration and for entertaining this request.

 

jon


Mac Pro, Mac OS X (10.6.8), 10.6.8 with 64 bit Win7 in Parallel
  • 1. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    MrHoffman Level 6 Level 6 (12,470 points)

    If you're seeking to maintain a list of recipients, then that tends to be a task that a customer relationship management (CRM) package would perform, or you might choose to use a package such as Apple's Address Book Server or equivalent, or (and this is less common) adding the target users into the LDAP directory.

     

    If one of these existing approaches and databases cannot meet your requirements, then it would then appear that hiring a programmer to code the necessary scripts and probably a Cocoa tool might be the most expedient approach for you.  (Importing data and updating the contents is typical of most database applications.)

     

    I don't know that Apple documents and supports a way to extract the previous recipients for you; you'd end up with some code that accesses the ~/Library/Application Support/AddressBook/MailRecents-v4.abcdmr database (all of which would likely be undocumented and subject to change by Apple) and that then merges its contents with your preferred contact database using the Cocoa Address Book framework or whatever is appropriate for the target database.

     

    The alternative being to add the users to the Address Book or LDAP directory database before sending the messages, rather than extracting the contact addresses from "underneath" Mail.app.

  • 2. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    Not sure to perfectly understand what you are asking for. What about a script that would do the following:

        1. Open Mail's “Previous Recipients” window.

        2. Select all the rows which have no icon in the first column, that is all the previous recipients who are not already in you contacts (the Address Book).

        3. Add the name and email address of each of the selected rows to an already existing “Previous recipients” group in your contacts (the Address Book).

        4. Remove the selected rows from the “Previous Recipients” window.

  • 3. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    Maybe you might want to try the following script. In this beta version, it doesn't delete any contact in the “Previous Recipients” window.

     

    set theNewNames to {}

    set theNewEmails to {}

     

    tell application "Mail"

        launch

        activate

    end tell

     

    -- Get all the previous recipients:

    tell application "System Events" to tell process "Mail"

        click menu item "Previous Recipients" of menu 1 of menu bar item "Window" of menu bar 1

       

        keystroke "a" using command down -- select the whole contents of the search field

        key code 51 -- remove it

        keystroke tab

        keystroke "a" using command down -- select all the rows

       

        tell rows of table 1 of scroll area 1 of window "Previous Recipients"

            set theCardIcons to image 1

            set theNames to value of text field 1

            set theEmails to value of text field 2

        end tell

    end tell

     

    -- Get only the previous recipients who are not already in your contacts:

    repeat with k from 1 to (count theEmails)

        if (item k of theCardIcons is missing value) then

            copy (item k of theNames) to the end of theNewNames

            copy (item k of theEmails) to the end of theNewEmails

        end if

    end repeat

     

    -- Get the first and last names if possible -- that's the weakest part of the script

    set theNewFirstNames to {}

    set theNewLastNames to {}

    repeat with thisName in theNewNames

        set theFirstName to ""

        set theLastName to ""

        if (thisName is not "") and ("@" is not in thisName) then

            try

                set theLastName to word -1 of thisName

                set theFirstName to text 1 through word -2 of thisName

            end try

        end if

        copy theFirstName to the end of theNewFirstNames

        copy theLastName to the end of theNewLastNames

    end repeat

     

    -- Add those previous recipients to the contacts, in the “Previous recipients” group:

    tell application "Contacts"

        launch

        activate

        set theGroup to group "Previous recipients"

       

        repeat with k from 1 to (count theNewEmails)

            set thisFirstName to item k of theNewFirstNames

            set thisLastName to item k of theNewLastNames

            set thisEmail to item k of theNewEmails

            set thisPerson to make new person with properties ¬

                {first name:thisFirstName, last name:thisLastName}

            make new email at end of emails of thisPerson with properties ¬

                {label:"eMail", value:thisEmail}

            add thisPerson to theGroup

        end repeat

       

        save

        set selected of theGroup to true

       

        display dialog "Done. (" & (k as text) & " contacts added.)" buttons {"OK"} default button 1 with icon 1

    end tell


  • 4. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    hi mrH.

     

    thank you. i have been trying hard to figure out how to do this on the mac. can you help me a little more here?

     

    i really don't want to have to do any coding or extreme customization at the same time i /do/ need to knit things together and they are not together at the moment. i have been considering using something like Google Contacts to sync everything and i have been asking questions about LDAP even though i don't know anything about LDAP or how it works. I have also been trying to figure out what kind of CRM tools i should look at (if any).

     

    my situation is simply that i have a small business with an almost finished set of BUSINESS CARD contacts in a CardScan database which has a large amount of contacts. my understanding is that the new version of this software syncs with AddressBook/Contacts. I /also/ have these "Previous Recipients" which are pretty much now in Mail after having been in outlook express, then outlook, then postbox etc, etc. at the same time my Address Book/Contacts database simply has important phone numbers in it.

     

    can you explain how AB Server works? how LDAP works?

     

    also can you help me a bit by what you mean about adding a user to Address Book or LDAP (manually i assume?) as opposed to "under" Mac Mail? I mean, adding contacts to CARDSCAN should be easy enough for me and adding contacts to ADDRESS BOOK/CONTACTS should be easy enough for me - and since these are apparently going to sync together (god i hope this works in a way that doesn't mash all the data together in a way that makes it impossible to use) it would be great.

     

    /if/ it is possible to simply "port" these contacts to AB/Contacts in a way that gets the data "over" so that i can use autocomplete in Mac Mail on all my devices this may in fact be the ideal solution unless i am missing something mission critical. since the data is added automatically to this database and since i /could/ create a "Previous Recipients on Mac Pro" and a "Previous Recipients on MBP" folders in AB/Contacts this may be enough.

     

    but i feel like i have been trying to map my own path through this stuff for about ten years so now that i am on mac i would really welcome finally solving it...

     

    THANKS

  • 5. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    hi pierre!

     

    THANK YOU.

     

    i was quite happy to find your other post related to this type of script. this has been a really big problem on my end and i have been trying for the last year or two since i ported to mac to see if i can solve it.

     

    can i please ask you to tell me in a sort of step by step way how to make this work? i have used automator before but i am not so good at it. also, i want to make sure i create folders and do the pickorder in the correct manner.

     

    also, am i correct in thinking that running this script would put all the Previous Recipients on my Mac Pro and all the Previous Recipients on my MacBook Pro in two folders in my Contacts/Address Book? then when i think i have a lot of new previous recipients added to this database i could simply run it again, yes?

     

    this would be really great and really an important development over here...

     

    THANKS

  • 6. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    also, am i correct in thinking that running this script would put all the Previous Recipients on my Mac Pro and all the Previous Recipients on my MacBook Pro in two folders in my Contacts/Address Book? then when i think i have a lot of new previous recipients added to this database i could simply run it again, yes?

     

    As I said in my very first post in this thread, I'm “not sure to perfectly understand what you are asking for”. That is due in part to my limited knowledge of English, but mainly to the complexity of your problem. Although I'm not too bad at programming in AppleScript, I don't know much about databases, mobile devices, networks, iCloud and so on. So the above paragraph of yours, where you are talking about two computers, two folders and a database, is a very good example of what I don't actually understand. Sorry…

     

    That being said, here's what the script should do, based on my (maybe incorrect) understanding of what you were asking for when you wrote: “can anyone code up a script that would let me simply add all the PREVIOUS RECIPIENTS data to a FOLDER in Contacts”.

     

    The script should:

    1. Launch Mail.app if that application is not already open.

    2. Open Mail's “Previous recipients” window (menu “Window”, menu item “Previous Recipients”).

    3. Get the name and email address of each of the previous recipients who are not already in your Address Book.

    4. Open Contacts.app (formerly AddressBook.app), if that application is not already open.

    5. Create a new card in your Address Book for each one of these new contacts, without overwriting anything.

    6. Assign all these new cards to the “Previous Recipients” group.

    7. Display a dialog when it is done (after at least several seconds).

     

    In its present state, the script won't delete any contact in the “Previous Recipients” window, nor in your Address Book. Then, if you like, you can delete all the new content of your “Previous recipients” group in your Address Book, and run the script as many times as you want in order to test it.

     

    BEFORE RUNNING THE SCRIPT, the only one thing you have to do, if not already done, is create a new group in your Address Book named "Previous recipients". If you fail to do that, however, the script will just return an error message (Contacts got an error: Can’t get group "Previous recipients".), but won't do any harm to any of your databases. Nevertheless, be sure (as always) to have a backup of all your data.

     

    TO RUN THE SCRIPT, just copy and paste it in a new AppleScript Editor window, and click the Run button. Please note that the script has been tested under Mac OS X 10.8, and might not work properly under any older version.

     

    I hope these explanations were clear enough and will help you solve your problem. If not, I hope some other more competent members could help you.

     

    Message was edited by: Pierre L.

  • 7. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    hi pierre.

     

    thank you. this is awesome and a great help. i will try it here shortly and hope i don't get stuck in applescript.

     

    can i please ask you two questions here?

     

    1. am i correct in saying that the script will simply over-write existing contacts in Contacts/Address Book with ones that are /already/ existing in the "Previous Recipients" folder in Contacts/Address Book and then /add/ anything that is new? the reason i ask is that i believe i have to leave existing entries in Previous Recipients in this list in Mac Mail and that i will have to run the script once in awhile to update the new entries. and i just want to make sure that /re-running/ the script will simply add the /new/ entries.

     

    2. is it possible to get a prompt to name the destination folder when in the script - or (maybe even better) to /select/ an existing folder in some way? the reason i ask is that, unless mac fixes this issue, i would want to run this script for /both/ my macpro and for my macbookpro. right now i am not sure if it makes sense to keep this data in two SEPARATE folders in Contacts/Address Book or if it makes sense to put it all in ONE folder in Contacts/Address Book but i can see that i will need to run the script on /both/ machines (which each has different data) AFAIK.

     

    - jon

  • 8. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    Hi Jon,

     

    Not that I don't want to help you, but I'm sure the best way to get a clear answer to your questions is to test the script by yourself first.

     

    Please do this:

    1. Create a new group (File menu > New Group) in your Address Book.

    2. Name this new group “Test Group”.

    3. In the script, just replace this one line of code:

        set theGroup to group "Previous recipients"

        with this one:

        set theGroup to group "Test Group"

     

    Then test the script by running it as many times as you want.

     

    In order to delete all the new cards added to your Address Book by the script, do this:

    1. Select the Test Group.

    2. Select all the contacts in the Test Group (⌘A).

    3. Select “Delete Cards” in the Edit menu (only available when at least one contact is selected).

    4. Click the button “Delete” in the dialog window (and not “Remove from Group”)

     

    And don't be afraid: the script will not over-write any of your already existing contacts.

     

    Hope it can help.

     

    Message was edited by: Pierre L.

  • 9. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    2. is it possible to get a prompt to name the destination folder when in the script - or (maybe even better) to /select/ an existing folder in some way?

     

    Yes. You could just replace this one line of code:

        set theGroup to group "Previous recipients"

    with these ones:

        display dialog "In which already existing group do you want to add the previous recipients?" buttons {"Cancel", "Previous recipients 1", "Previous recipients 2"} default button 2 with icon 1

        if button returned of result is "Previous recipients 1" then

            set theGroup to group "Previous recipients 1"

        else

            set theGroup to group "Previous recipients 2"

        end if


  • 10. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    hi pierre.

     

    ok. thank you.

     

    i have to dedicate a morning to some of these trickier (for me) computer issues so i hope to make this work.

     

    the problem i have is that i had been testing Previous Recipients sync with Contacts and it is still a very buggy interface. i tried some things and it corrupted my Contacts which meant i had no access to my phone numbers. also, despite my backing up the Contacts database, there is some really complicated issue with iCloud where one cannot simply restore the database. this resulted in a two full-day troubleshooting with advanced techs over the course of a week or two to finally get this fixed. so - i am really concerned not to have to do this again because it is a big problem to spend time on something like this for me.

     

    regarding the deleting of the contacts in Contacts database i understand that i can remove these.

     

    1. do you have any insight as to whether duplicates will not overwrite data in the Contacts database? i had this problem when i tried to port these from the Mail Previous Recipients database but perhaps this was due to the new contacts not going into a dedicated folder?

     

    2. do you have any insight as to whether it will be possible to run this script over time when - new Previous Recipients are added - and to simply allow the new addresses to get ADDED? i mean, i won't be deleting the older addresses in Previous Recipients that were already added and i just want to make sure that i won't be re-adding these to the database. i mean, if i have to do this sort of thing manually by sorting manually it may make more sense to do it all manually now.

     

    - jon

  • 11. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    Sorry again, Jon, but I am actually unable to answer these questions. Before reading your first post, I was not even aware of the existence of that Previous Recipients window, which I had never used. As I said before, I don't know much about databases and iCloud. That's the reason why I urged you to try the script by yourself.

     

    However, the only thing I can say (again) is this: running the script will add new cards to your Address Book, maybe duplicates, but won't over-write any of your previous cards. And as those duplicates will be in your “Previous recipients” group, it will be easy to get rid of them without deleting any one of your original cards.

     

    I can't do more for now…

     

    Message was edited by: Pierre L.

  • 12. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    ok. thanks.

     

    i will post back when i try to test it.

     

    THANK YOU!

  • 13. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    hotwheels 22 Level 1 Level 1 (0 points)

    hi pierre.

     

    i want to thank you (THANK YOU!!) for helping me with this.

     

    i have run this on my macbookpro and will run it on my mac pro this evening. i have changed the names of the destination folders and then added these folders to contacts. i also had to turn on allow assisted devices in preferences > accessibility.

     

    so far it seems like it is working perfectly but i will test more in the coming days. it solves a /huge/ problem for me and was really easy to implement on my end. very nice to get going with applescript as well.

     

    THANK YOU

    THANK YOU

    THANK YOU

     

    jon

  • 14. Re: Mail Previous Recipients "port" to /folder/ in Contacts
    Pierre L. Level 4 Level 4 (3,860 points)

    i also had to turn on allow assisted devices in preferences > accessibility.

     

    Yes, I failed to mention that GUI Scripting (tell application "System Events" to tell process "Mail") requires access for assistive devices be enabled. Sorry for that.

     

    so far it seems like it is working perfectly but i will test more in the coming days.

     

    I'm really glad I could help you. Many thanks for your feedback.

1 2 3 Previous Next