2

My goal is to be able to highlight a number of messages in Apple Mail then run a process to print them each to a PDF. Right now I can select multiple emails command + P Then select PDF -> Save as PDF but that saves all the highlighted emails as an single PDF file. I'm looking to get an individual PDF per highlighted email (with the subjst as the PDF file name if possible).

I looked at Automator's Print Plugin but couldn't find a way to create separate documents (can't say I'm any sort of Automator pro so I may have overlooked something obvious)

Is there some way for me to accomplish this using Automator or applescript?

4
  • Seems like it'd be easy enough to Applescript this. You can find example loops for selected messages in Mail all over the Internet. I'll noodle something up, but it'll be harder for me to test as I won't use Mail. Commented May 6, 2020 at 16:26
  • @MarcWilson If not mail, what do you use for your client? I only ask because this would be even better with outlook but I figure that's not as apple script friendly.
    – Jason
    Commented May 6, 2020 at 17:06
  • I find Fastmail's web client to be more than sufficient. I run that in a SSB. I use Mail.app on iOS. Won't use Outlook... the idea that an application in 2020 doesn't support CalDAV/CardDAV (plus Outlook/iOS incredible stupidity wrt contacts generally) keeps me far away from it. Having said that, yes, it's Applescript-able. Commented May 6, 2020 at 17:12
  • Good to know...I've been contemplating moving my personal mail to Fastmail. I'm stuck with Outlook for work :-(
    – Jason
    Commented May 6, 2020 at 17:50

2 Answers 2

2

This following AppleScript code will save single or multiple selected email messages as individual PDF files. Each PDF file will be named as the subject of the selected email message.

This solution works for me using the latest version of macOS Catalina.

tell application "Mail" to activate

tell application "System Events" to tell application process "Mail"
    repeat until frontmost
        delay 0.1
    end repeat
    tell menu bar 1 to tell menu bar item "File" to tell menu "File"
        tell menu item "Export as PDF…" to perform action "AXPress"
        delay 1 -- Value May Need To Be Adjusted
    end tell
    repeat until sheet 1 of window 1 exists
        delay 0.1
    end repeat
    if UI element "Choose" of sheet 1 of window 1 exists then
        -- When Multiple Email Messages Are Selected
        click UI element "Choose" of sheet 1 of window 1
    else
        -- When Only One Email Message Is Selected
        click UI element "Save" of sheet 1 of window 1
    end if
end tell
2

While I know you've asked about automating this via AppleScript/Automator; nonetheless, let me offer a different, possibly better, approach in which a keyboard shortcut is assigned to the existing Export as PDF… command on the File menu in Mail.

You would then be able to select the message(s) and press, e.g., ⌘D then Enter to have the message(s) exported to individual PDF files. Also, by semi-automating this, it gives you the opportunity to select where you want the exported PDF document(s) to go, if other then what's already selected. (This is not a current option with the fully automated solution offered in the other answer.)

To assign a keyboard shortcut to the existing Export as PDF… command, go to:

  • System Preferences > Keyboard > Shortcuts > App Shortcuts
  • Click the [+] button.
  • In the sheet that appears:
    • Application: Mail
    • Menu Title: Export as PDF…
    • Keyboard Shortcut: ⌘D
    • Click the Add button, or press Enter

Hint: Copy and paste Export as PDF… as it uses an ellipsis at the end, not three separate dots. Also note that ⌘D was chosen as it was not, by default, already in use in Mail.

1
  • This works as described but for a few other reasons I'm going to stick to the applescript option.
    – Jason
    Commented May 9, 2020 at 23:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .