Open Link In Multiple Emails And Download File From Website

New to Keyboard Maestro and trying to figure out if this is something I can build.
I’ve got a group of 100+ emails that all contain a link to a secure messaging website that then has a link to a file I need to download. Each email and secure message look exactly the same. What I’m trying to do is automate the below process.

1.	Open link in Outlook (Mac or web app)
2.	Download file on messaging website
3.	Close tab
4.	Loop the process for the remaining emails.

Some random notes
• Browser I use is Chrome but can also run Safari
• I do have my email account in Apple Mail as well but rarely have the app open
Please let me know if there is a similar thread as well.

Hey @bbech,

Welcome to the forum!   :smile:

You say you're using Microsoft Outlook as your mail client?

What version?
On what version of macOS?

Your task should be possible up to the download.

The download part I wouldn't guarantee – it depends upon how difficult the source site makes it.

-Chris

This automation is very doable, but will require substantial skills and at least several hours to produce.

Here is an untested outline of how I would approach this. This specific outline is untested, but I have done a number of similar projects.

Almost all of the heavy lifting for this requires scripting: AppleScript and JavaScript in Browser, and Regular Expressions (Regex).

  1. Select the messages in Outlook that you want to process
  2. Execute an AppleScript action that get the messages selected
    1.extracts the body HTML of each message
    2. uses Regex to extract the link in that message.
    3. Returns a list of URLs to open
  3. Use a KM For Each action on this URL list.
    1. Open the URL
    2. Use Execute a JavaScript in Front Browser action to get the HTML element that contains the download link.
    3. Use JavaScript to click() this element
    4. Use KM to set the download folder
    5. Pause until download is completed.

Development of this automation could easily take many hours, depending on the complexity of the email messages and the web page with the file to download.

Thanks everyone for the suggestions. I was able to figure out a way to do it triggering for each individual email, mostly using keyboard and clicking automation.

@JMichaelTX thank you for a quick outline. I think like you said it may take longer than it’s worth for the task to make it fully automated but I’ve figured out a workable solution

If you don't mind sharing, it would be great if you could upload your final macro. I'm sure this would help a lot of other KM users.

See How to upload your macro. Instructions for uploading to an existing post are just below the main instruction.
You may also find this Macro useful: MACRO: Upload KM Macro to New or Existing Topic @KM [Pub].