Changing filename of *.eml files in finder

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Changing filename of *.eml files in finder Sun Apr 12, 2020 7:29 am • by luponero
Hi there BrainsTrust,

I am filing MS Outlook mail into Finder by dragging the MS Outlook mail items into Finder. I then want to use Hazel to change the file name. I'd like the rename the file with pattern: date name extension...which I have figured out successfully :D

With the date pattern I'd like to use the date the mail was sent to me (data from MS Outlook) and this does not seem to be an option even if I look in the "Other" area and look at all the attributes.

Is there a way to do this? I have tried all date options to no avail. Any help will be appreciated.

Regards luponero :?:
luponero
 
Posts: 5
Joined: Sat Jul 14, 2012 3:31 am

You can try using "Contents contain match" and try to match it in the contents of the file. Try using Hazel's preview function to see if the file's contents are available there.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Changing filename of *.eml files in finder Sat Apr 18, 2020 11:06 pm • by luponero
Thanks Mr Noodle...that worked.

As I am now trying to be more creative I am also trying to incorporate the email addresses (to and from) into the filename. I have tried every "other" attribute for renaming but nothing picks up the information I need.

Any tips from the brainstrust?

Thank in advance
luponero
 
Posts: 5
Joined: Sat Jul 14, 2012 3:31 am

Is it available to extract from the contents?
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Changing filename of *.eml files in finder Fri Apr 24, 2020 11:56 pm • by luponero
Mr_Noodle wrote:Is it available to extract from the contents?

Unfortunately I can't see any addresses from the contents. I am not sure why :?:

I have tried to use the "other" naming conventions to no avail. I just can' locate or extract an email address.
luponero
 
Posts: 5
Joined: Sat Jul 14, 2012 3:31 am

In that case you may need to use a script.
Mr_Noodle
Site Admin
 
Posts: 11236
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:In that case you may need to use a script.

Thanks. I'll see what I can work out. Never tried a script but always happy to learn.
luponero
 
Posts: 5
Joined: Sat Jul 14, 2012 3:31 am

Re: Changing filename of *.eml files in finder Tue Sep 01, 2020 5:44 pm • by nm1
luponero wrote:
Mr_Noodle wrote:In that case you may need to use a script.

Thanks. I'll see what I can work out. Never tried a script but always happy to learn.


You can use the following AppleScript to capture the header information into their own variables, which you can then use in Hazel to name the file as you like:

Code: Select all
set pFile to quoted form of (POSIX path of theFile)
   set {mDate, mSubject, mFrom, mTo} to every paragraph of (do shell script "cat " & pFile & " | grep -e Date: -e Subject: -e From: -e To:")


In terms of the Sent/Received timestamp, you can either use Hazel's functionality to turn the mDate variable into timestamp format, or else you can do it with AppleScript:

Code: Select all
-- trim mDate beginning at char 12 to end of line
   set mDate to trim(mDate, 12)
   set mTime to trim(mDate, 13)
   set mFrom to trim(mFrom, 7)
   
   -- capture elements of mDate into components
   set {mDay, mMonth, mYear} to every word of mDate
   set theDate to mMonth & space & mDay & space & mYear
   
   --capture elements of mTime into components
   set AppleScript's text item delimiters to ":"
   set {h, m, s} to every word of mTime
   set theTime to h & m & s
nm1
 
Posts: 13
Joined: Thu Jul 12, 2018 2:18 pm


Return to Support