Save emails from Outlook as PDF (ideally with sender info in filename)

Hi,

before Yosemite I was using mail.ap and had a pretty good macro to save email, especially bills and receipts automatically as PDFs in my archive folder. However Apple removed a function I desperately need (don’t ask :smile:) from mail.app and I have to move back to Outlook for Mac.

Does anyone have a good script to automatically saving emails as PDF (ideally with the sender’s name and the date sent in the filename) and/or does anyone how I can access the senders name or email address and the date it was sent from outlook within a KM macro? In mail.app I was just using the variable %MailSender%, but I have no idea how to do that in Outlook.

If someone had a script or a similar solution, I should be able to adapt it to my needs, so any pointers are welcome.

Thank you, Julian

Hi,

I with the help of another post here, I am able to automate most of this, by clicking buttons. I can even check if the save dialog is already in the right folder and if not, change into the folder. At the end I add todays date (in reverse ISO notification) and do the rest manually (My dialoges are in German; but I am sure you can figure out what they mean):


Maybe my 80% solution helps someone who struggles with the same issue. However, I'd still be very happy if someone had a smarter way to generate the PDF and I desperately need an idea how to access the sender's email address and the date the email was sent.

Is there a way to query stuff from outlook like date and sender address if the currently highlighted email? If I get a pointer there, I am sure that I can figure out the rest. Thanks for any help. Julian

Hey Julian,

It can be done with AppleScript.

tell application "Microsoft Outlook"
  set _message to selection
  tell _message
    
    # See what properties are available:
    set messageProperties to properties
    
    # A couple of examples of getting properties:
    set senderName to name of (get sender)
    set senderEmail to address of (get sender)
    set msgSubject to subject
    set msgRecievedDate to time received as text
    
  end tell
  
end tell

Saving as .pdf isn't all that hard either.

# Produces an alias to the Desktop
set ouputPath to (path to desktop)

# Transform our Desktop alias into a file-url complete with file name.
tell application "Finder"
  set ouputPath to URL of ouputPath & "OutLook_Print_Test.pdf"
end tell

tell application "Microsoft Outlook"
  set _message to selection
  print _message with properties {as pdf:true, path name:ouputPath}
end tell

NOTES:

Outlook produces a single item for the selection when only 1 item is selected.

It produces a LIST-Object when more than 1 item is selected.

Both scripts are written to work only with 1 item selected.

--
Best Regards,
Chris

Chris, thanks for your sample Applescript code.
I’m a very new KM user. How can I get those Applescript variables into KM variables?

Thanks.

Hey There,

Off-air a few days due to a really gnarly flu-bug…

Run these in sequence starting with 1 & 2 in the Applescript Editor to see how they work.

# Create New Keyboard Maestro Variable with content:
tell application "Keyboard Maestro Engine"
  make new variable with properties {name:"myVariableName", value:"myVariableValue"}
end tell

# Get Value of Keyboard Maestro Variable:
tell application "Keyboard Maestro Engine"
  set appleScriptVariable to value of variable "myVariableName"
end tell

# Change Value of Keyboard Maestro Variable:
tell application "Keyboard Maestro Engine"
  set value of variable "myVariableName" to "NUTS!"
end tell

--
Best Regards,
Chris

1 Like