1

I'm trying to get a text document list of any links in a bunch of email messages that reside in the latest Mac Mail.app (OS X 10.10.2 Yosemite), and am simply stumped.

I thought I'd be able to just...

  1. Put a couple of Automator.app actions together in a Service/Workflow,
  2. Select/highlight all the email messages within the Mail.app,
  3. Select that Service or run that Workflow,
  4. And have a text document with every URL/link that could be found within them all.

However, this didn't work.

I figured out how to do this with one email message at a time, but that's not what I want. attached is a screenshot of 3 workflows. The first one is the one that works with just one email message & highlighting all the text in it & running the Service. the other two just simply don't work.

I also notice that the the first shows up in the Service Menu with a single email open; once I highlight more than one email message, the option goes away from the Service menu.

Any tips or tricks?

screenshot

1 Answer 1

6

I figured out how you could reach your goal, start with creating a new service within Automator (input: "No input", application: "Mail")

The first action is Get Selected Mail Messages (Get selected: messages)

The second action is Execute AppleScript with the following script:

on run {input, parameters}
    set mailContentList to {}
    tell application "Mail"
        repeat with selectedMail in input
            set end of mailContentList to content of selectedMail
        end repeat
    end tell
    return mailContentList
end run

This script simply walks through the given messages, reads out the content and passes this list to the next action

The third action is Extract URLs from Text. This is listed as "Extract Data from Text" and one of the types of data is "URLs".

And the final action is New TextEdit Document

Save it with a nice name like Extract URLs from selected mails After that the Service is available inside the Services menu inside the Mail app.

In my test I found a few internal URLs without http:// from links to anchors, so maybe you want to delete all URLs that do not start with http. You can do so by using another action before creating the new TextEdit document:
Filter Paragraphs with options "Paragraphs that start with http" (don't know how these parameters are called in English Automator, sorry)

Feel good, Michael / Hamburg

2
  • Can confirm it works great! As noted here, if you want to extract links from the e-mail’s HTML body (rather than visible text) use source of selectedMail instead of body. Jun 18, 2017 at 15:10
  • 1
    To filter duplicate urls, add an extra step ‘Run AppleScript’ to the workflow: (* Strip duplicates *) on run {input, parameters} set filteredList to {} repeat with i from 1 to count of items of input if item i of input is not in filteredList then set filteredList to filteredList & item i of input end if end repeat return filteredList end run (adapted from here) Jun 18, 2017 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.