Previous 1 2 3 Next 39 Replies Latest reply: Jul 30, 2014 2:04 PM by Kaptain Kazi
MrFindlay Level 1 Level 1 (0 points)

I saw this post which has been archived. I need to know how to apply the script?

 

--

 

 

 

The following script should extract all email addresses from the body of the selected messages, and put them into the clipboard. It should then be easy to paste the contents of the clipboard into a Numbers or Excel document.

 

*set theAddresses to ""*
try
*set TID to AppleScript's text item delimiters*
*set AppleScript's text item delimiters to space*
*tell application "Mail"*
*repeat with theMessage in (get selection)*
*set theText to text items of (get content of theMessage)*
*repeat with thisItem in theText*
*if thisItem contains "@" then*
*set theAddresses to theAddresses & (thisItem as text) & return*
*end if*
*end repeat*
*end repeat*
*end tell*
*set the clipboard to theAddresses*
*set AppleScript's text item delimiters to TID*
*on error*
*set AppleScript's text item delimiters to TID*
*end try*
*the clipboard*

 

--

  • Austin Kinsella1 Level 6 Level 6 (11,520 points)

    Paste the lines with the * into Script Editor. Remove the * from the ends of each line and click the compile button to check the syntax. Select a couple of messages in Mail then click Run in Script Editor and see what happens. If you save it in your Library/Scripts/Applications/Mail then itshould be available for running from the scipt menu when Mail is active.

  • MrFindlay Level 1 Level 1 (0 points)

    Thank you so much... it's still running the script for 8000 emails, but I did the test and it works.

     

    How do I open the scipt menu for mail?

  • Austin Kinsella1 Level 6 Level 6 (11,520 points)

    The script menu is for all applications, but where scripts are stored in the appropriate folders, only scripts for a specific application show when that app is active. If you are on 10.6.8, the folder is ~/Library/Scripts/Applications/Mail (~ represents your home directory). If you haven't the script menu showing in your toolbar, should run Applscript Utility from Applications/Applescript to enable it.

     

    (Note: I seem to have lost my Applications/Applescript folder. Also, I think that the user scripts system might have change a bit under 10.7 or 10.8)

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

    Unfortunately, although the script I posted on May 10 seems to have done what Raltham was asking for, it was nonetheless seriously flawed. Here's an improved version, which takes into account the case where an email address is preceded or followed by a line feed (character id 10) or a carriage return (character id 13):

     

    set theAddresses to ""

    try

        set TID to AppleScript's text item delimiters

        set AppleScript's text item delimiters to {space, character id 10, character id 13}

        tell application "Mail"

            repeat with theMessage in (get selection)

                set theText to text items of (get content of theMessage)

                repeat with thisItem in theText

                    if thisItem contains "@" then

                        set theAddresses to theAddresses & (thisItem as rich text) & return

                    end if

                end repeat

            end repeat

        end tell

        set the clipboard to theAddresses

        set AppleScript's text item delimiters to TID

    on error

        set AppleScript's text item delimiters to TID

    end try

    the clipboard


     

    Message was edited by: Pierre L.

  • MrFindlay Level 1 Level 1 (0 points)

    The new script is coming up with a syntax error. Expected class name but found application constant or consideration!

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

    Sorry, but I'm unable to reproduce the syntax error you are talking about. The new script seems to work properly on my MacBook Pro, at least under Mac OS X 10.8 Mountain Lion. I select a few messages in Mail and run the script from the AppleScript Editor window. Admittedly, the script is not fast, but it does work.

     

    Could you give more details about that syntax error?

  • MrFindlay Level 1 Level 1 (0 points)

    I've cut and paste the following code into a new script window and it won't let me compile it:

     

    set theAddresses to ""

    try

    set TID to AppleScript's text item delimiters

    set AppleScript's text item delimiters to {space, character id 10, character id 13}

    tell application "Mail"

    repeat with theMessage in (get selection)

    set theText to text items of (get content of theMessage)

    repeat with thisItem in theText

    if thisItem contains "@" then

    set theAddresses to theAddresses & (thisItem as rich text) & return

    end if

    end repeat

    end repeat

    end tell

    set the clipboard to theAddresses

    set AppleScript's text item delimiters to TID

    on error

    set AppleScript's text item delimiters to TID

    end try

    the clipboard

     

     

    Any ideas?

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

    Sorry again, but I've had no problem compiling and running the exact code you just posted.

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

    it might be a copy/paste issue - sometimes when you copy from web browsers you get html artifacts (non-breaking spaces, html entities...) that will confuse the applescript editor.  try copying it into textwrangler and run the zap gremlins command.

  • MrFindlay Level 1 Level 1 (0 points)

    Tried Gremlin zap. But it made no difference. I did notice that the syntax error was highlighting the following words in the applescript:

     

    *rich text*

     

    in the following line of script

     

    *set theAddresses to theAddresses & (thisItem as rich text) & return*

     

    Yet the original script compiled with no problems even though the line of code is the same!?

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

    well, the next thing to try (and I know this sounds silly) is to delete the phrase 'rich text' and retype it (don't copy/paste).  When you compile an applescript it doesn't save as text, it saves using codes that represent applescript objects. if it saves with the wrong code (which occasionally happens for a number of odd reasons) it can throw a compile error even though the text looks correct.  deleting and retyping clears the underlying code and forces it to recompile.

  • MrFindlay Level 1 Level 1 (0 points)

    I've tried that already and it did not work. I've tried cleaning the text in several ways, as a graphic designer I'm used to it as clients send you all kinds of trash text.

     

    I've asked a friend who I know has mountain lion if he can do it for me, but he's gone away for a week without his laptop! I'm running 10.6.8 with scripteditor 2.3.

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

    well, there's only a limited number of reasons it would be giving this error.  I don't have my 10.6 partition handy, so please open the mail scripting dictionary and make sure that it supports rich text as a class rather than as a property of some other class.  if it has its own heading in the Text Suite then it's a class, if not, it's a property of a different class and won't work the way you're using it. 

  • MrFindlay Level 1 Level 1 (0 points)

    The mail dictionary states this...

     

    A set of basic classes for text processing.

    textn, pl text : Rich (styled) text

    elements

    contains paragraphs, words, characters, attribute runs, attachments.

    properties

    color (color) : The color of the first character.

    font (text) : The name of the font of the first character.

    size (number) : The size in points of the first character.

Previous 1 2 3 Next