Print multiple email messages from Apple Mail to individual PDFs

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?


Solution 1:

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

Solution 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.