Thank you very much for your latest answer.
First of all, if anything was misunderstood, it might be because English is not my native language and I used a translation tool.
Here’s a bit of background:
In Safari, I use a macro that goes through every single tab in the frontmost window and exports each one as a PDF. The idea came from this thread:
https://forum.keyboardmaestro.com/t/export-all-open-safari-tabs-to-pdf/19332
With that in mind, about one and a half years ago I thought there should be something similar for Mail. That’s why I kept the title of my original thread rather general. Extracting links was just one example — there are many possible applications.
For instance, I’d like to export multiple emails as PDFs (the current case), but also perform other actions like setting multiple flags or moving several emails at once.
Of course, I could write separate JXA or AppleScripts for each task, but since my coding skills are limited, I prefer to handle things using Keyboard Maestro’s built-in functions whenever possible. Thanks to ChatGPT, I’ve meanwhile built up a nice little collection of short AppleScripts and other scripts I created myself.
The email printing workflow is a special case. I’ve been using Keyboard Maestro since late 2018 / early 2019, and printing emails has been my last “unfinished project.” ChatGPT has helped a lot here as well.
For public or work-related emails, I use a timestamp in the filename, and with Hazel (executing a Shortcut) plus ChatGPT, the files are renamed automatically. For private emails, I use the sender and subject instead (as described above).
I’ve been thinking about how to archive around 10,000 old emails in bulk. I’ve tried different approaches — Export as PDF, Print workflows, Print Services, custom keyboard shortcuts (à la MacSparky), and of course .eml files were also an option.
In fact, I had already asked a question about .eml files back in 2019:
https://forum.keyboardmaestro.com/t/email-automation/14165
None of the methods really convinced me back then. Only recently, with the help of ChatGPT, I discovered how many more options there actually are.
Still, Apple Mail remains somewhat buggy, which is why I opened another thread — because, according to Google AI, there’s supposedly a three-step solution I couldn’t quite get to work.
Your suggestion now goes exactly in that direction.
Regarding the specific issue:
When I select, say, five emails for the loop, the script runs five times, but each time it processes four selected emails plus the first unselected one. This happens for both of your scripts, at least on my system.
However, I tested again yesterday and realized this doesn’t actually matter for my main use case — printing 10,000 old emails or saving as eml files.
By flagging each processed email and moving it to another folder after printing, I can easily work around this issue. I just want to get rid of those old emails anyway.
Also, creating .eml files is quite simple with a bit of AppleScript help.
One last question, if I may:
People here often recommend tools like Hazel, BBEdit, or HoudahSpot — I use them all.
But could you recommend any advanced .eml management app besides Apple Mail?