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

    That means that in 10.6 there wasn't a separate 'rich text' class, that was subsumed under the 'text' class.  Delete the word 'rich' and it should compile and work properly.

  • MrFindlay Level 1 Level 1 (0 points)

    That's worked, thanks, your a star 

     

    Is there a way to add to the script to ignore or delete certain full email addresses?

     

    And to ignore or delete brackets?

  • twtwtw Level 5 Level 5 (4,900 points)

    I don't know what you mean by 'brackets'.  You need to give more detail because the immediate answer to the first question (use an IF statement) is much too simplistic to be what you meant.

  • MrFindlay Level 1 Level 1 (0 points)

    When the script was running the data the results would be...

     

    my@domain.com

    (other@domain.com)

    my@domain.com

    (another@domain.com)

     

    I've sorted it with a simple find and replace. But it would be good if the script could do it, even if it's just to save 5 mins work.

  • WALTER-MILANO-ITALY Level 4 Level 4 (2,175 points)

    Do you mean the adress extracted as follows:

    <name@domain>name@domain  ???

    I tested some of the scrips posted in this discussion and I got sometimes this result.

    Than I used the script posted by Pierre L. and I got only the name@domain.

     

    Tu further work on the extracted list I would copy and paste into a wordprocessor and than work on it wit search and replace..

  • twtwtw Level 5 Level 5 (4,900 points)

    if you're talking about angle brackets - <someone@somewhere.com> - then you'll find it easiest to use Mail's extract address from command:

     

              if thisItem contains "@" then

                        set theAddresses to theAddresses & (extract address from thisItem)

              end if


    Alternately, you can expand the text item delimiters to include angle brackets, which will effectively remove them from the text.

  • Pierre L. Level 5 Level 5 (4,140 points)

    Maybe you might want to try the following script, which should be much faster than the previous one:

     

    set theEmailAddresses to ""

     

    tell application "Mail"

        repeat with thisMessage in (get selection)

            set R to my getEmailAddresses(content of thisMessage)

            if R is not "" then set theEmailAddresses to theEmailAddresses & R & return

        end repeat

    end tell

     

    on getEmailAddresses(theText)

        set theAddresses to ""

       

        repeat

            set j to offset of "@" in theText

            if j = 0 then exit repeat -- no email addresses in this message

            set thisAddress to "@"

            set L to length of theText

           

            set k to j

            repeat

                set k to k - 1

                if k = 0 then exit repeat

                set C to item k of theText

                if C is in {" ", "<", "(", character id 10, character id 13} then exit repeat

                set thisAddress to C & thisAddress

            end repeat

            set N1 to (count thisAddress)

           

            if N1 > 1 then

                set k to j

                repeat

                    set k to k + 1

                    if k > L then exit repeat

                    set C to text item k of theText

                    if C is in {" ", ">", ")", character id 10, character id 13} then exit repeat

                    set thisAddress to thisAddress & C

                end repeat

                set N2 to (count thisAddress)

                if N2 > N1 then set theAddresses to theAddresses & thisAddress & return

            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 getEmailAddresses

     

    theEmailAddresses

     

    Message was edited by: Pierre L.

  • MrFindlay Level 1 Level 1 (0 points)

    Faster and as clean as a whistle... your a legend

  • Pierre L. Level 5 Level 5 (4,140 points)

    My pleasure. I'm glad I could help you.

  • WALTER-MILANO-ITALY Level 4 Level 4 (2,175 points)

    Hi Pierre L.

    The script you published  started my interest in this programming.

    I am 65 and started to use computers in 80s.... Dos, TurboBasic, later Windows and finally Mac from 2008.

    I think it is time to play some scripts but as a beginner I have now simple questions. Will you help me to start ?

     

    I pasted your list into Scripteditor.  If I try to compile I do not understand what happens, I am not able to find a script or an app which could be run.

    If I try to Record (green button with circle) nothing happens and the only possible way out is pressing Stop.

    But I can save the file and i get a file.scpt which works perfectly: it opens in the script editor and I can run it and it does what is expected.

     

    What I'm not understanding  ?

    Is there a book on Apple scrpts which do you suggest ?

     

    Thanks for your time.

    Walter

  • Pierre L. Level 5 Level 5 (4,140 points)

    Hi Walter,

     

    Before trying to compile and run scripts, maybe you should have a look at the AppleScript Editor's help menu.

     

    To learn AppleScript, I strongly suggest that you start by reading this: Beginner’s Tutorial: The First Step.

     

    Then you could have a look at the AppleScript Language Guide.

     

    Good luck!

  • muzaa Level 1 Level 1 (0 points)

    Hi!

    I would like to ask you for help.

     

    How to add to extracting from the body, extracting email addresses from

    email header from field "Sender (From)"

     

    I opened discussion https://discussions.apple.com/thread/4913975.

     

    Thank you very much for help, I can't get it from anywhere.

  • Pierre L. Level 5 Level 5 (4,140 points)

    How to add to extracting from the body, extracting email addresses from

    email header from field "Sender (From)"

     

    Just try replacing

     

    tell application "Mail"

        repeat with thisMessage in (get selection)

            set R to my getEmailAddresses(content of thisMessage)

            if R is not "" then set theEmailAddresses to theEmailAddresses & R & return

        end repeat

    end tell

     

    with

     

    tell application "Mail"

        repeat with thisMessage in (get selection)

            set theEmailAddresses to theEmailAddresses & reply to of thisMessage & return

            set R to my getEmailAddresses(content of thisMessage)

            if R is not "" then set theEmailAddresses to theEmailAddresses & R

            set theEmailAddresses to theEmailAddresses & return -- optional

        end repeat

    end tell

     

    in the script.

     

    Message was edited by: Pierre L.

  • muzaa Level 1 Level 1 (0 points)

    Thanks Pierre!

     

    I tried to do something in automator once from one website.

    It was extracting email addresses from archived mail account.

     

    I don't know how to use your script.

    I guess I can use it in Automator in "Run AppleScript".

     

    I saw that has to be deleted spaces between lines after copy/paste from "web" to "Run AppleScript".

     

    I did it and now I get Syntax Error: Expected “end” but found “on”.

     

    The error is highlighted here:

     

    on getEmailAddresses(theText)

        set theAddresses to ""

     

    What do I do wrong please? I can't get it working from anywhere. I have thousands emails and I have to extract all email addresses from two email accounts...

     

    Thank you for help and advice!

  • Pierre L. Level 5 Level 5 (4,140 points)

    I don't know how to use your script.

    I guess I can use it in Automator in "Run AppleScript".

     

    As for me, I know practically nothing about Automator.

     

    Try this:

     

    1. Launch Mail.

    2. To begin with, select just a few emails in one of your email inboxes.

    3. Launch AppleScript Editor.

    4. Copy and paste the whole script into the AppleScript Editor window

    5. To run the script, just click the Run button.

     

    A list of email addresses should appear at the bottom of the AppleScript Editor window.

    You might then copy those addresses and paste them for example into a new TextEdit document.

     

    Message was edited by: Pierre L.