Scrape a date from an email

I have an Automator workflow set up to get photo attachments from selected emails in Mail. I then have Hazel sort those photos by date. The problem is even though the email may have been sent in 2011, the Date Created, Date Opened, Date Modified on the picture all appear as today. Sometimes Content Created will work and sometimes it won’t. Is there a way to automatically take the date of the email, write the metadata to the picture so that Hazel can classify it into folders for the correct year?

Have you tried the “Date Taken (Hazel)” attribute of the photo?

It looks like all the exif data has been stripped from the pictures so that won’t work

Sounds like you might want to use, for example, ExifTool to set the metadata from the command line. You can then automate that on the command line to update your saved image in a working directory somewhere.

Then just grab the date from the selected e-mail (a bit of AppleScript in your Automator action should suffice), and include it in your command line operation to update the saved image.

After that, have Automator move the image from your working directory to your Hazel processing directory and you should be good to go for having Hazel sort it to its final destination.

Hope that helps.

1 Like

Thanks for your help. That’s way beyond my ability level, but I’ll keep learning.

Just do it one step at a time and if you get stuck, come back, share how far you have got and someone will be able to help you with the next step.

Automator has a run shell script action that you can use to run things on the command line. For the EXIF data it will be one command and you can lookup the documentation for the app I referenced.

The AppleScript discussion should probably also get you very close if not spot on for getting the date that you want. You just use an Automator Run AppleScript action for that.

As for file moves, I’m sure that you must have come across those in Automator before.

Give it a try, with the forum as your safety net for if you get stuck. You might just surprise yourself with how far you get. :grinning: