Previous 1 2 3 Next 39 Replies Latest reply: Jul 30, 2014 2:04 PM by Kaptain Kazi Go to original post
  • muzaa Level 1 Level 1 (0 points)

    Thanks!

     

    I copy/paste the script to TextWrangler>Zap gremlins> copy/paste to AppleScript>RUN

     

    Then I get Syntax Error: Expected “,” but found identifier.

     

    It's highlighted L:

     

    if (k  L) or (j = L) then exit repeat

    set theText to text (j + 1) through -1 of theText

    end repeat

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

    Why don't you just paste the whole script (and just the script) directly from the Apple Discussions into the AppleScript Editor window?

     

    The right code should be:

     

            if (kL) or (j = L) then exit repeat

            set theText to text (j + 1) through -1 of theText

        end repeat

     

    Message was edited by: Pierre L.

  • muzaa Level 1 Level 1 (0 points)

    Thanks Pierre!

     

    Now it´s working but i get apart of emails things like this:

     

    <namea@gmail.com>

    [mailto:nameb@gmail.com]

    namea@gmail.com
    Subject:

     

    or

     

    Tom Jones <tom.jones@yahoo.com>

    tom.jones@yahoo.com

     

    Is it possible to put in the script how to delete duplicates and sort emails please?

     

    Is this correct?

     

    grep -Eiorh '([[:alnum:]_.-]+@[[:alnum:]_-]+?\.[[:alpha:].]{2,6})' "$@" | sort | uniq

     

     

    I don't know how to add it to your script.

     

    Thanks again

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

     

    Is this correct?

     

    grep -Eiorh '([[:alnum:]_.-]+@[[:alnum:]_-]+?\.[[:alpha:].]{2,6})' "$@" | sort | uniq

     

     

     

    I can't tell. I don't know much about UNIX either. Sorry!

     

    Here's an improved version of the previous script that's more robust and removes duplicates. To sort emails, however, use Excel or Numbers or please ask someone else to help you.

     

    Admittedly, AppleScript is not the best way to go if you have hundreds of mails to handle.

     

     

    global leftDelimiters, rightDelimiters

     

    set whiteSpaceConstants to space & tab & return & linefeed ¬

        & character id 8232 & character id 160

    set leftDelimiters to whiteSpaceConstants & "<([:;"

    set rightDelimiters to whiteSpaceConstants & ">)]:;,?!"

    -- modify the above delimiters if necessary

     

    set theEmailAddresses to {} -- a list

    set theRef to a reference to theEmailAddresses

     

    tell application "Mail"

        repeat with thisMessage in (get selection)

            try

                copy (reply to of thisMessage) to the end of theRef

                repeat with thisAddress in my getAddresses(content of thisMessage)

                    copy contents of thisAddress to the end of theRef

                end repeat

            end try

        end repeat

    end tell

     

    -- Remove duplicates :

    set theShorterList to {}

    repeat with thisAddress in theRef

        set thisAddress to contents of thisAddress

        if thisAddress is not in (theShorterList as text) then

            copy thisAddress to the end of theShorterList

        end if

    end repeat

     

    -- Convert the list to text (as a list of paragraphs) :

    set TID to AppleScript's text item delimiters

    set AppleScript's text item delimiters to return

    set theText to (text items of theShorterList) as text

    set AppleScript's text item delimiters to TID

     

    -- Display the result in a new TextEdit document :

    tell application "TextEdit"

        make new document at front with properties {text:theText}

        activate

    end tell

     

     

    on getAddresses(theText)

        set theAddresses to {}

       

        repeat

            set j to offset of "@" in theText

            if j = 0 then exit repeat -- no more email addresses

            set thisAddress to "@"

            set L to length of theText

           

            set i to j

            repeat

                set i to i - 1

                if i = 0 then exit repeat

                if (text item i of theText) is in leftDelimiters then exit repeat

            end repeat

           

            set k to j

            if i + 1 < j then

                repeat

                    set k to k + 1

                    if k > L then exit repeat

                    if (text item k of theText) is in rightDelimiters then exit repeat

                end repeat

                if k - 1 > j then

                    set thisAddress to text (i + 1) through (k - 1) of theText

                    if last character of thisAddress is "." then

                        set thisAddress to text 1 through -2 of thisAddress

                    end if

                    copy thisAddress to the end of theAddresses

                end if

            end if

           

            if (kL) or (j = L) then exit repeat

            set theText to text (j + 1) through -1 of theText

        end repeat

       

        return theAddresses

    end getAddresses

     

     

    That's the best I can do. Hope it can help.

     

    Message was edited by: Pierre L. (replaced “repeat with thisAddress in theEmailAddresses” with “repeat with thisAddress in theRef”

  • muzaa Level 1 Level 1 (0 points)

    Thank you Pierre! Works!

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

    Thanks for your feedback.

     

    I think the script could be improved a little bit further by replacing

     

    set theShorterList to {}

    repeat with thisAddress in theRef

        set thisAddress to contents of thisAddress

        if thisAddress is not in (theShorterList as text) then

            copy thisAddress to the end of theShorterList

        end if

    end repeat

     

    with

     

    set theShorterList to {}

    set theRef2 to a reference to theShorterList

    repeat with thisAddress in theRef

        set thisAddress to contents of thisAddress

        if thisAddress is not in (theRef2 as text) then

            copy thisAddress to the end of theRef2

        end if

    end repeat


  • muzaa Level 1 Level 1 (0 points)

    It works for me same like the other one, maybe it's faster I don't know.

    It's perfect. Thank you

     

    The result of the script I have to pass through another email extractor to delete all names and brackets.

     

    Now I get results like this for example:

     

    adwords-noreply@google.com

    ivan gimenez <iva-gime@hotmail.com>

    david bravo suarez <dabrasu@hotmail.com>

    info@companyfree.eu

     

    Is there any way in the script how to get only the email address without the name please?

     

    What do you mean with this please? It´s at the end of one of your posts:

    Message was edited by: Pierre L. (replaced “repeat with thisAddress in theEmailAddresses” with “repeat with thisAddress in theRef”

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

    Is there any way in the script how to get only the email address without the name please?

     

    Hopefully, the following version of the script should do exactly what you are asking for (except sorting):

     

     

    global leftDelimiters, rightDelimiters

     

    set whiteSpaceConstants to space & tab & return & linefeed ¬

        & character id 8232 & character id 160

    set leftDelimiters to whiteSpaceConstants & "<([:;"

    set rightDelimiters to whiteSpaceConstants & ">)]:;,?!"

    -- modify the above delimiters if necessary

     

    set theEmailAddresses to {} -- a list

    set theRef to a reference to theEmailAddresses

     

    tell application "Mail"

        set N to 0

        repeat with thisMessage in (get selection)

            try

                copy (extract address from reply to of thisMessage) to the end of theRef

                repeat with thisAddress in my getAddresses(content of thisMessage)

                    copy contents of thisAddress to the end of theRef

                end repeat

                set N to N + 1

            end try

        end repeat

    end tell

     

    -- Remove duplicates :

    set theShorterList to {}

    set theRef2 to a reference to theShorterList

    repeat with thisAddress in theRef

        set thisAddress to contents of thisAddress

        if thisAddress is not in theRef2 then

            copy thisAddress to the end of theRef2

        end if

    end repeat

     

    -- Convert the list to text (as a list of paragraphs) :

    set TID to AppleScript's text item delimiters

    set AppleScript's text item delimiters to return

    set theText to (text items of theShorterList) as text

    set AppleScript's text item delimiters to TID

     

    -- Display the result in a new TextEdit document :

    tell application "TextEdit"

        make new document at front with properties {text:theText}

        activate

    end tell

     

     

    on getAddresses(theText)

        set theAddresses to {}

       

        repeat

            set j to offset of "@" in theText

            if j = 0 then exit repeat -- no more email addresses

            set thisAddress to "@"

            set L to length of theText

           

            set i to j

            repeat

                set i to i - 1

                if i = 0 then exit repeat

                if (text item i of theText) is in leftDelimiters then exit repeat

            end repeat

           

            set k to j

            if i + 1 < j then

                repeat

                    set k to k + 1

                    if k > L then exit repeat

                    if (text item k of theText) is in rightDelimiters then exit repeat

                end repeat

                if k - 1 > j then

                    set thisAddress to text (i + 1) through (k - 1) of theText

                    if last character of thisAddress is "." then

                        set thisAddress to text 1 through -2 of thisAddress

                    end if

                    copy thisAddress to the end of theAddresses

                end if

            end if

           

            if (kL) or (j = L) then exit repeat

            set theText to text (j + 1) through -1 of theText

        end repeat

       

        return theAddresses

    end getAddresses

  • muzaa Level 1 Level 1 (0 points)

    Perfect!!!

     

    How can I give you "This solved my question"?

     

    Thanks a lot

  • Kaptain Kazi Level 1 Level 1 (0 points)

    Hi Pierre,

    I've gone through your script and it works, it takes out the email address found inside the body of an email.

    Would you be able to help me, i receive emails from eBay with my customers information as below:

    I want to extract the FULL NAME, EMAIL ADDRESS & HOME ADDRESS on a text file or csv. If you

    can please help me with this, i would be ever most gratefull. Thanks

     

     

    You did it. Your item has sold. Please dispatch this item to the buyer within 1 working day(s) after your buyer pays. As soon as your buyer pays, print your eBay postage label.
    3 reasons to print your label on eBay:
    • Get discounted rates for postage.
    • eBay label printing service is free.
    • Tracking information is uploaded automatically to My eBay and an email is sent to your buyer that their item is on the way.

    If you don't use eBay label printing, upload your tracking information manually.

     


    You should always leave Feedback for your buyer to encourage them to buy from youagain.

     

    New Skinny Mens Wedding Solid Denim Blue Plain Necktie Tie 2.5" UK Seller
    New Skinny Mens Wedding Solid Denim Blue Plain Necktie Tie 2.5" UK Seller
    End time:07-Aug-14 19:03:14 BST
    Sale price:£5.47
    Quantity:3
    Quantity sold:1
    Quantity remaining:2
    Buyer:Sam Smith
    sams6187 (sams@4highgreen.com) [contact buyer]

     

    Buyer's postal address:

     

    Sam Smith
    23 Sammy Lodge
    Sam Road
    Bamford, Derbyshire S45 9CY United Kingdom
    Sell another item | Send invoice to buyer
Previous 1 2 3 Next