« Saving email attachments with pre-pended YYYY-MM-DD_ - Take 2 | Main | Controlling a powerUSB power strip from python on Mac OS X »
Saturday
Feb142015

Saving email attachments with pre-pended YYYY-MM-DD_

Multiple times a week I receive an email with attached report files that I need to save for one reason or another. I save these to a few different folders, depending on type of report. The filenames of these attachments are often unchanged from the last N times I received this type of report. So, I like to prepend the date in the form "YYYY-MM-DD_..." to the filename.

(As an aside: I do not trust email attachments for longer-term archival storage. I've had too many attachments, as in a dozen or more, be corrupted months or years later when I tried to re-access them.)

This is an easy task that is ripe for automation.


Everything above this line is True. Everything below, well, let's just say it worked when I wrote the draft of the post, and stopped working moments after I clicked Publish. See this next post for an updated version that actually works

Edited to add: If you are running 10.10 Yosemite (or maybe 10.9), this may not work reliably. See this thread about issues with AppleScript access to Mail.app attachments. So, good luck & no guarantees...


Below is an AppleScript that does this to the attachments of the selected email message. There are many ways to trigger this AppleScript, but in my case I've created a simple workflow in Alfred.

The only thing I haven't figured out is why Default Folder X isn't active in my Alfred-triggered AppleScript. It was when I ran it from Script Editor. Weird.

And, here's the AppleScript: