[MlMt] Creating a bundle template for message data, including attachments

P crp at f-m.fm
Fri Oct 1 12:13:34 EDT 2021

Hello everyone,

I've been exploring the world of MailMate bundles recently. They are a 
great format for anything to be shared, or for relatively simple 
scripts. However, as some of my scripts have become more and more 
complicated, I've started to find my proliferating .mmcommand and 
executable files a bit unmanageable. Debugging can be particularly 

Given that the vast majority of my bundle commands would be of no use to 
anyone besides myself, I'm trying a different strategy: creating a 
simple script to pull out message information and send it to Keyboard 
Maestro in JSON format. Once in KM, it's easy to pass it to whatever 
script or app is needed. I also find it easier to keep everything 
organised this way.

Here's what the .mmcommand file looks like:

	name					=		'template';
	input					=		'canonical';
	environment		= 
	command			=		'#!/bin/bash\n"${MM_BUNDLE_SUPPORT}/bin/template"';
	keyEquivalent	=		'^[';
	uuid					=		'47d6808e-e6a7-41d9-9d92-d2948423be26';

And here's the executable:


cat > "${tmpFile}"

osascript <<END

tell application "Keyboard Maestro Engine"
	do script "${macro}" with parameter 
end tell


unlink "${tmpfile}"

As you can see, I put the KM macro ID into the environment variables, 
which allows a single executable file to send the JSONified data to any 
number of macros. I just have to create a new .mmcommand file each time.

The variables passed:

tmpFile (full-text of the message)

It takes a bit of detective work to figure out what the available 
environment variables are but I think I've gotten most of them. The one 
major thing that I've failed to figure out is how to get attachments.

In the [bundle 
under "inputFilesPattern," it's mentioned that attachments are 
accessible via the `MM_FILES` environment variable. However, I've found 
only one example of this in use ([by David 
It's written in Python—a language that, unfortunately, I don't know 
very well. Consequently, I'm struggling to see how it works or how it 
could be adapted.

So, long story short, I am wondering if anyone has any other examples of 
getting attachment info from `MM_FILES`, or some advice on how I could 
integrate it into my above-mentioned template.

I know that `MM_FILES` itself provides data in JSON format, which can be 
tricky to parse in AppleScript, but there are several ways around that. 
I just can't seem to get anything from that environment variable, which 
makes me think that I must be missing something.

Many thanks,

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freron.com/pipermail/mailmate/attachments/20211001/aa62a4b0/attachment.htm>

More information about the mailmate mailing list