Rename EML Files with Date-Time-Subject

I am looking to rename many eml files in a folder with the date+time received and keep subject of the email such as in this help article:

https://discussions.apple.com/thread/8189528?page=2


However I also need the Subject of the email added.


Can anyone help?


These two Community Members seem to know alot about this, but I cannot message them directly.

https://discussions.apple.com/profile/HD

https://discussions.apple.com/profile/VikingOSX

iMac Line (2012 and Later)

Posted on Oct 17, 2019 7:13 AM

Reply
Question marked as Top-ranking reply

Posted on Oct 21, 2019 6:26 AM

Ok, after some more research, I figured out my own answer:


Add the lines:

try

set the_subject to (do shell script "grep -m 1 ^\"Subject: \" " & the_path)

on error

set the_subject to "No Subject"

end try



I also added in these lines to remove some invalid characters in the email subjects.


set the_subject to replace_chars(the_subject, ": ", "-")

set the_subject to replace_chars(the_subject, ":", "-")

set the_subject to replace_chars(the_subject, "/", "-")

set the_subject to replace_chars(the_subject, " :(", "")


-- A sub-routine for replacing characters in strings:

-- http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html

Similar questions

3 replies
Question marked as Top-ranking reply

Oct 21, 2019 6:26 AM in response to avanspro

Ok, after some more research, I figured out my own answer:


Add the lines:

try

set the_subject to (do shell script "grep -m 1 ^\"Subject: \" " & the_path)

on error

set the_subject to "No Subject"

end try



I also added in these lines to remove some invalid characters in the email subjects.


set the_subject to replace_chars(the_subject, ": ", "-")

set the_subject to replace_chars(the_subject, ":", "-")

set the_subject to replace_chars(the_subject, "/", "-")

set the_subject to replace_chars(the_subject, " :(", "")


-- A sub-routine for replacing characters in strings:

-- http://www.macosxautomation.com/applescript/sbrt/sbrt-06.html

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Rename EML Files with Date-Time-Subject

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.