AppleScript Integration

If you are use of Mac OS X Mail, you can automate the opening of winmail.dat files with TNEF's Enough. The following AppleScript is triggered from a Mail Rule and will save the winmail.dat file to you Downloads folder before opening.

Feel free to use this as a starting place for a script that best fits your needs. Feedback, suggestions and requests are welcome.


The Script

Open Script Editor (Applications/Utilities) and create a new script. Copy and paste the following into the script window and save with a name like OpenWinmailFiles.scpt. Save the script to your desktop for now and read "Configure Script" below for where to place it.


  using terms from application "Mail"
  on perform mail action with messages theMessages for rule theRule
    tell application "Mail"
      repeat with eachMessage in theMessages
        -- wrap in try to catch errors and display them
        try
          repeat with theAttachment in eachMessage's mail attachments
            -- get name of attachment and proceed if winmail.dat
            set originalName to name of theAttachment
            if originalName is equal to "winmail.dat" then
              -- build path to save file
              set downloadsFolder to (((path to home folder) as rich text) & "Downloads") as rich text
              set savePath to (downloadsFolder & ":" & originalName)
              -- find unique name
              set pathIterator to 1
              tell application "Finder"
                repeat while exists file savePath
                  set savePath to (downloadsFolder & ":winmail-" & pathIterator & ".dat")
                  set pathIterator to pathIterator + 1
                end repeat
              end tell
              -- save file
              save theAttachment in savePath
              -- open file
              tell application "Finder"
                open savePath using application file id "com.joshjacob.TNEFsEnough"
              end tell
            end if
          end repeat
        on error theerror
          display dialog theerror buttons {"Ok"} default button 1
        end try
      end repeat
    end tell
  end perform mail action with messages
end using terms from
                    

Mail Rule

The AppleScript is configured through Mail's Preferences Rules tab. Choose "Add Rule" and under "Perform the following actions" select "Run Applescript". The next drop down will give you the option to select the script to run.

The script won't appear until it's in the correct folder. Select "Open in Finder" to get to the correct folder in the Finder. You can then copy the above script that you saved to your Desktop into Mail's AppleScript folder and select it.


Have Feedback?

Let me know if you have any problems with using TNEF's Enough or if you have suggestions for future versions. My time to answer emails is a bit spotty to say the least but I'll try my best to answer your questions.

TNEF's Enough for macOS
FAQ
Icon