Skip navigation

Mail Previous Recipients "port" to /folder/ in Contacts

2401 Views 37 Replies Latest reply: Aug 29, 2012 1:47 PM by hotwheels 22 RSS
  • Pierre L. Level 4 Level 4 (3,860 points)

    can i please just ask you for a version that puts the information in a group named "previous recipients" and one that puts the information in a group named "previous recipients_MBP".

     

     

    The following very slightly modified version of the script puts the information in a group named "previous recipients". To get a version that puts the information in a group named "previous recipients_MBP", just replace "previous recipients" with "previous recipients_MBP" in the very first line of the script. Absolutely no way to go wrong here!

     

     

    set theGroupName to "previous recipients" -- or any other name that fits your needs

     

    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

        key code 51 --   to remove the whole contents of the search field

        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

        keystroke "w" using command down -- close the "Previous Recipients" window

    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 theGroupName

        set theAlreadyAddedEmails to (value of email of people of theGroup) as text

        set k to 0

        repeat with j from 1 to (count theNewEmails)

            set thisEmail to item j of theNewEmails

            if not (thisEmail is in theAlreadyAddedEmails) then

                set thisFirstName to item j of theNewFirstNames

                set thisLastName to item j of theNewLastNames

                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

                set k to k + 1

            end if

        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 giving up after 2

    end tell


  • Pierre L. Level 4 Level 4 (3,860 points)

    any ideas on fixing this pierre?

     

    No, sorry.

     

    The only thing I can do is try to explain once more, as precisely as I can, what the script does. The script:

    • lists all the emails it finds in Mail's "Previous Recipients" window;

    • removes from that list all those emails which are in rows beginning with a card icon, in other words all those contacts which are already in your Address Book;

    • adds the rest of the emails to the "previous recipients" group already existing in your Address Book, provided they do not already exist in that group, in order not to create duplicates.

    That' all!

     

    On my MacBook Pro, under OS X 10.8, everything seems to work flawlessly, so that I really don't understand why it doesn't work on your MacBook Pro.

     

    Sorry, Jon, but this post will be my very last one in this thread.

     

    Message was edited by: Pierre L.

1 2 3 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.