Select Most Recent Download and Attach to an Airmail Message

Hi All,

Forgive me, absolute newbie and still tinkering & learning!

I want to set up a command to open Airmail, create a new email to a specific email address, insert a standard subject, then attach the most recent downloaded file on my computer and send....

I am up to the attach the file bit and am a bit lost. Will I also need to start teaching myself AppleScript??? Eek!

Have you considered using the built in KM action to send a mail message, with attachment, instead of AirMail? (I have no idea what Airmail is.)

Airmail is an email client for macOS.

Keyboard Maestro's Send Mail Message action works strictly with Apple Mail.

Hey Claire,

I don't have Airmail to test with, but I strongly doubt its AppleScript suite included the ability to attach a file.

You'll probably have to brute-force the UI with Keyboard Maestro.


Everything you wrote is correct. But I asked him if he considered using the KM action instead of Airmail. The KM action might work much more easily for the problem he described.

I don't have Airmail installed, but if it lets you attach a file by pasting it into the email composer window, you might be able to use a For Each action and the Set Clipboard to File Reference action to place the most recently downloaded/added file in a folder onto the clipboard and pasting it:

Example Macro.kmmacros (2.4 KB)

Assuming attaching by pasting works, once you're sure the macro is placing the right file one the clipboard, you can enable the Paste action to further automate the process.

1 Like

I downloaded Airmail from the app-store, and looked at its AppleScript dictionary.

Airmail 5 has improved. It now has a mail attachment element in its outgoing message class, so it does look like this can be scripted.

Unfortunately I'd have to pay for the software to test it, so I can't divine the correct syntax. Something like this I'd guess:

set filePath to "posix path to your file"

tell application "Airmail"
   tell outgoing message 1
      make new attachment with properties {filename:filePath}
   end tell
end tell

I did look on the net for clues, but the pickings were very poor.


Your tip for getting the most recent file is good and is how I would do it. But I would like to add that I think he can do the paste into the KM "Send Mail Message" action. He doesn't have to use the AirMail client at all. Unless he likes complex solutions.

Thanks everyone! I am trying out some of these - slowly - as I don't know what I am doing really! I have downloaded the Macro but can't work out how to start it and at what point... I'll keep you posted!

Ignore last message. God I must sound stupid. So I have left some of my initial actions at the top and then added the macro... "Start airmail" "enter text" for the email address... is that right?

PS I'm a she!!! :wink:

Quite so, but most people who use a certain mail client don't like using another one.

If I remember correctly – the mail action's ability to send attachments has been broken for a while anyway:

Send Mail Message Text Transparent When Attaching File?

1 Like

No problem. Yes, the actions in the macro I uploaded are meant to go after the ones you have set up to activate Airmail and fill in the subject fields, etc. That all sounds right, but we'd really need to see your working macro to say for sure. If you're not sure how to upload a macro to the forum, you can find instructions here: Forum [Keyboard Maestro Wiki]

That said, you may want to test to see if you can copy and paste a file into the Airmail composer window to attach it before you proceed further, as the macro I uploaded won't be of much use otherwise.

It worked!!! I can't believe it that is so awesome!!! Thanks so much.
It has also pasted the text of the path into the email, but that doesn't really matter, unless it is easy to stop that from happening... Should I try and upload the current Macro? LOL, now I really am getting adventurous...

1 Like

You're welcome. Glad to hear it worked. There may be a way to stop the macro from pasting the file's path too, or at least to clean it up afterwards, but we can't say for sure without seeing what the output looks like. You're welcome to upload the macro you've got now for more feedback and to try and refine it further if you like (and if you do so, I'd suggest you also upload a screenshot of the Airmail composer once you've run the macro, so we know what sort of results you're getting) but if the path getting pasted doesn't really matter too much, and the macro is now doing what you want, and you're happy with the output, I'd say that's the main thing that matters.

Not really necessary, but thought I'd try this while I'm here:

Send most recent download to accounts@ Macro (v10.0)

Send most recent download to accounts@.kmmacros (6.7 KB)

1 Like

Nobody laugh ok!!!

It all looks fine to me. The main thing is that it's doing what you want, and if it's doing so with acceptably fast performance, even better.

I'm sorry about that. However both "Clair" and "Claire" are spellings that are used by both women and men.

Fantastic. Thanks again for your help!