<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hey Phillip</p>
<p dir="auto">Just came by accident across your post.</p>
<p dir="auto">Super cool that you do a lot with bundles - I want to do more with bundles too:</p>
<ul>
<li>
<p dir="auto">I am looking for a bundle/command which saves a message to a predefined folder without all the folder hierarchy the “Export - Copy to Folder” command creates.</p>
</li>
<li>
<p dir="auto">Also I would like to have a bundle to to save attachments to an additional fixed/preset location.</p>
</li>
</ul>
<p dir="auto">One day…</p>
<p dir="auto">Happy emailing,<br>
Leo</p>
<p dir="auto">On 2 Oct 2021, at 2:13, P wrote:</p>
<blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px">
<p dir="auto">Hello everyone,</p>
<p dir="auto">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 tricky.</p>
<p dir="auto">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.</p>
<p dir="auto">Here's what the .mmcommand file looks like:</p>
<pre style="border:thin solid gray; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px"><code>{
name = 'template';
input = 'canonical';
environment = 'macro=E61C4928-CE11-460D-ADD9-2B379C1BBB5D\nmsgID=${message-id.split}\nsubjectPrefix=${subject.prefix}\nsubjectBody=${subject.body}\nfromName=${from.name}\nfromAddress=${from.address}\ntoName=${to.name}\ntoAddress=${to.address}\ncontentType=${content-type.type}';
command = '#!/bin/bash\n"${MM_BUNDLE_SUPPORT}/bin/template"';
keyEquivalent = '^[';
uuid = '47d6808e-e6a7-41d9-9d92-d2948423be26';
}
</code></pre>
<p dir="auto">And here's the executable:</p>
<pre style="border:thin solid gray; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px"><code>#!/bin/bash
tmpFile="$TMPDIR/8D444CFE-C1F9-4F82-AD8B-4EA7EC7A77C2.eml"
cat > "${tmpFile}"
osascript <<END
tell application "Keyboard Maestro Engine"
do script "${macro}" with parameter "{\"tmpFile\":\"${tmpFile}\",\"msgID\":\"${msgID}\",\"subjectPrefix\":\"${subjectPrefix}\",\"subjectBody\":\"${subjectBody}\",\"fromName\":\"${fromName}\",\"fromAddress\":\"${fromAddress}\",\"toName\":\"${toName}\",\"toAddress\":\"${toAddress}\"}"
end tell
END
unlink "${tmpfile}"
</code></pre>
<p dir="auto">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.</p>
<p dir="auto">The variables passed:</p>
<p dir="auto">tmpFile (full-text of the message)<br>
msgID<br>
subjectPrefix<br>
subjectBody<br>
fromName<br>
fromAddress<br>
toName<br>
toAddress</p>
<p dir="auto">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.</p>
<p dir="auto">In the <a href="https://github.com/mailmate/mailmate_manual/wiki/Bundles#inputfilespattern">bundle documentation</a>, under "inputFilesPattern," it's mentioned that attachments are accessible via the <code>MM_FILES</code> environment variable. However, I've found only one example of this in use (<a href="https://github.com/slochower/bundles/tree/master/My%20Save.mmbundle">by David Slochower</a>). 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.</p>
<p dir="auto">So, long story short, I am wondering if anyone has any other examples of getting attachment info from <code>MM_FILES</code>, or some advice on how I could integrate it into my above-mentioned template.</p>
<p dir="auto">I know that <code>MM_FILES</code> 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.</p>
<p dir="auto">Many thanks,</p>
<p dir="auto">Philip._______________________________________________<br>
mailmate mailing list<br>
<a href="mailto:mailmate@lists.freron.com">mailmate@lists.freron.com</a><br>
<a href="https://lists.freron.com/listinfo/mailmate">https://lists.freron.com/listinfo/mailmate</a></p>
</blockquote>
</div></div>
</body>
</html>