Running shortcuts on email rules on macos?

I have an macos app calles Contacts journal. It has no applescript dictionary so as I understand it my only option is to use the shortcuts that are included with the app.

I managed to get a shortcut working to send an email to the log of the correct contact by searching contacts journal for the email sender and then add log to that contact. But I would like to automate the process by mail rules somehow. (I started using Mailmate as well)

In ios shortcuts you can ad automation for a contact, but then you would need to create an automation for every contact.

This is my shortcut:(the missing script on top i just “getting mail adress”):

I have no programming skills. Is there any other way than shortcuts to interact with contacts journal? I dont really have the knowledge about what you can do with scripts. Also on what levels are there “basic” support for all aplications? Does applications need a privided API, framwork, dictionary? Or are there a basic set of commands that kan be used on all apps?

I don’t know exactly what you want to do, but you can call any shortcut from AppleScript with parameters. This should also work from the Apple Mail Rules, where you can specify an Applescript to run.

Example:

using terms from application "Mail"
	on perform mail action with messages theMessages
		repeat with theMessage in theMessages
			set theSender to sender of theMessage
			tell application "Shortcuts Events"
				run shortcut named "Your Shortcut" with input theSender
			end tell
		end repeat
	end perform mail action with messages
end using terms from

If you need more than one parameter, take a look here:
Example of passing parameters to a Shortcut and getting the return

In simple terms i just want an applescript that takes the email content and message id link. With that text i want to create a log entry in my CRM app. The only option to get the log into the CRM app is to use its Shortcuts.app support.

Right now the shortcut that includes applescripts is made to grab data from the selected email in mail.app. And that wouldnt work with an apple mail rule running script.

1 Incoming mail with certain criteria, SCRIPT (grab mail id and text from mail) 2 Extract sender mail and search for contact in Contacts Journal 3 IF contact found: add email with message id link as a log entry in Contacts journal.

I have very basic knowledge about this, so im sorry if my explenation is a bit unclear. :slight_smile:

Ok, but that works with the example script:

Simply call up a Shortcut with the necessary parameters using Applescript as a mail rule (every incoming mail) and then do everything else in this.

Or I still haven’t understood the workflow.

Based on your script, here is an example of a Shortcut that is called for each new incoming (or filtered) E-Mail and separates the data into the following variables:

  • senderName
  • senderAddress
  • emailSubject
  • emailURL
  • emailBody

You can then log these in your CRM-Tool or wherever you want in the Shortcut-App.

Mail-Rule Script (Mail → Settings → Rules):

using terms from application "Mail"
	on perform mail action with messages theMessages
		repeat with theMessage in theMessages
			set theMessageId to message id of theMessage
			tell application "Shortcuts Events"
				run shortcut named "Log E-Mail" with input theMessageId
			end tell
		end repeat
	end perform mail action with messages
end using terms from

Shortcut:
Log E-Mail

Note:
Execution may take some time as the email is called up again by id in the shortcut app, as the e-mail body may be too large to be transferred as a parameter.