Trigger KM macro by incoming email


#1

What I am looking for: a macro triggered by an email

My situation:
I sometime do some freelance work for a company. They email me and other people who work for them will tasks they want us to do. The first person to go to the website, login na click on a confirmation link gets the job. What I would like to do is to have keyboard maestro go to the website and do the confirmation for me everytime an email from them land in my gmail inbox. So the macro should be triggered by an email containing certain text.

What is important: response time. I need the confirmation on the website to be made ASAP. If I am late someone else will take the job.

  • My mac mini is running 24/7 so the solution doesn’t have to be energy efficient or elegant.
  • The solution may include dropbox, ifttt, google drive or hazel if needed.

Thanks a lot for your help


Mail macro trigger?
#2

Thanks for using Keyboard Maestro.

Since your post is NOT a finished, published, macro, I have moved it to the “general” category.

Please see the guidelines for posting in the “macro” category:

Good luck with your project.


#3

Keyboard Maestro does not have any trigger for mail arriving.

It is possible something like Mail Act On could trigger an AppleScript which could trigger a macro which could do what you want.


#4

I know that Outlook for Mac has the ability to have rules for incoming mails, which triggers an AppleScript.
And an AppleScript can trigger a KM macro.
Maybe Apple Mail has the same functionality.

I think this is the route you need to persue.


#5

Hey Bartłomiej,

Apple Mail’s rules can run AppleScripts.

Such AppleScripts must be located in this folder:

~/Library/Application Scripts/com.apple.mail/

using terms from application "Mail"
  on perform mail action with messages messageList for rule theRule
    
    tell application "Mail"
      repeat with theMessage in messageList
        set msgSubject to theMessage's subject
        display notification "Mail Message" with title msgSubject subtitle "arrived" sound name "Sosumi"
        
      end repeat
    end tell
    
  end perform mail action with messages
end using terms from

You can get the contents or source of a message and parse it for what you need.

Personally I’d use the Satimage.osax AppleScript Extension to do the parsing and open the given URL in Safari – but you can also use the AppleScript to populate Keyboard Maestro variables and call a Keyboard Maestro macro.

This little task is NOT as simple as most people want it to be, but it’s doable.

Google for “Apple Mail rules AppleScript”.

AppleScript help is available on the Applescript Users List and on MacScripter.net.

-Chris


#6

I get an email with the subject ’ “Apply Now” Form - Contact form on’ these emails automatically appear in the junk I have in Mail a rule for Mail to then put these emails into the main Inbox. When ever I get these emails I would like to trigger a macro which will extract data from the email and save as a variable into KM. For the non techincal KM users could you provide a recipe of how we can get KM to trigger a macro when ever the email is received?

Many thanks for your assistance, greatly appreciated.


#8

In this same rule, you can run a script, as shown above by @ccstone.

Is there some reason that this will not work for you?


#9

I’ve got it working thanks.