Automatically attaching a specific file to an email

Hi guys,

I was hoping someone could give me some advice. I’m struggling to build (of find examples on the KM forum of) a macro that will allow me to attach a specific file into a email and was wondering if you could help.

What I’m trying to do is create a macro which will automatically attach a specific word doc into an email (using Mac mail). Ideally I’d like to do this in the background so I don’t have to navigate away from the email. I’ve been playing with the ‘Copy File’ widget but I don’t think it’s the right approach as it needs a destination file to paste it to. I thought that I could use named clipboards but while they allow you to paste an image into them for later use they don’t seem to allow you to have a Word doc as a paste-able element.

To take you through what I’m hoping to achieve…

  1. I open Mac Mail app and start composing a new mail.
  2. I press a hot key. The macro copies a specified file from my desktop in the background and then pastes it into the mail. This will be the same file each time and so doesn’t need a dialogue box. I’ll assign different hot keys to different specified files

Does that make sense? Any pointers about which mechanism to use would be very welcome.

Thanks

Rob

If I flip the order of your actions I think this could work.

Use the Open File action, where you choose the file, and then set the application to be Apple Mail.

Then you will start with at new message, where the file is attached.

It could look like this. I use Outlook as email-program. You can change this to Apple Mail.

Another solution would be to use AppleScript, which could target the active message, and then attach the file.

I am now AppleScript master, but maybe some other could offer up a solution.

I do something like this in attaching customer invoices (first I download them to /tmp/url.pdf, and then I attach them, and the latter half is what you need to do).

Assuming the message window is open and Mail is at the front, this is the sequence I use. Basically, select Attach Files…, then use Command-Shift-G and type the file path in to select it, and then press return. Lots of pausing for the system to animate windows and keep up.

Keyboard Maestro Actions.kmactions (1.5 KB)

2 Likes

Hey Jimmy,

This can't be done with Mail after a new message is created.

You can create and manipulate a new message with AppleScript, but once it's created it is essentially dead to scripting. (Other than UI-Scripting.)

-Chris

Hey Rob,

This macro will place the given file on the clipboard for pasting.

It will then do all the work for you in Mail's frontmost outgoing message.

The file will be pasted at the end of the message.

The cursor will be returned to the last text on the page (if there is any), or the beginning of the page (if there is not any text).

Currently it will only work with 1 file, although I'm looking into how to paste multiple files at once.

It's fast and should be relatively bombproof.

-Chris


Mail -- Paste File into Front Outgoing Message.kmmacros (13 KB)

That’s tremendous. Thanks everyone - this is super helpful. I tried both Jimmy’s and Peter’s methods this morning and they both work very well. Jimmy’s has the advantage of being quicker, but Peter’s allows me to do it with the email already open and created.

It looks like Chris’ one is probably going to be the bees knees. I haven’t had a chance to install it yet, but I thanks so much for going to all the effort to put it together Chris. I’ll have a look at it this evening and let you know how I get on.

Thanks again and have a great day.

rob

2 Likes

Cheers Chris. I’ve just tried it out and it works perfectly - it’s very cleverly done. This will be tremendously useful to me and save me a whole heap of time each week. I hope others find it as useful - I’d imagine there a are a lot of folks like me and Peter who regularly need to embed standard docs/pdfs in their mail.

Thanks again.

Rob

Hey Rob,

Good deal.

Here's how to put a reference to one or more files and/or folders onto the clipboard.

AppleScript – Getting References to Files and/or Folders onto the Clipboard for Pasting

-Chris

I've just come across this and am glad (cause it means I'm on the right track!) that Peter doesn't have a better solution than what I was beginning to realise I would need to use. However, I have noticed that it simply doesn't work on my mac, and that was annoying.

After 10 minutes or so of googling what on earth could be going wrong with the ⇧⌘G hotkey in the open attachment dialog, I discovered that Lastpass.app was eating the shortcut. Lastpass has it assigned by default to generate password, but the window for that doesn't open because Mail has priority (I assume). Frustrating, but hopefully it might save somebody else some hassle to see this comment.

2 Likes