Automatically Convert Word Documents to PDF


Updated thanks to Mac Power User listener Corwin Carr - MPU Episode 186 with script at MPU Evernote document

The Issue

I have issues with a lot of the Microsoft Word documents I receive at work when I open them on my iPad. The documents are often complex and the format is garbled. As always, I need to do these things securely because of confidentiality of work documents. So web services are out. Also, iPad apps that convert don't usually solve my formatting issues. What does work is saving in PDF natively from Word.

The Design of the Solution

Here's my current solution. I set up a folder on my work Box account. That folder is watched by Hazel. On seeing the Word document, Hazel runs a script to open the document in Word on my Mac and saves it as a PDF back to the Box folder.

This solution assumes that you have a copy of office for Mac, a "always on" Mac to be available to you via a synced folder on a cloud service, and the corresponding cloud app on your iPad. This could be Box or Dropbox or even your Tranporter. Since I either have my Mac with me and I can read the file natively or I'm using my iPad and my Mac is back at my desk and available, this works for me. It should work for many of you with your always on Mac Mini!

How it Works

I use the open in feature on my iPad in the mail app to upload the document to the watched folder via my Box app. After the sync occurs to my Mac, the script fires and the PDF is created. Box syncs the document to the cloud and I have my easy to read and annotate (in Notability or Notes Plus) PDF on my iPad.

An Aside

Back when I first started my Mac productivity "Hobby", I had looked for a solution on the net and found this post with a solution by spazek. I was new to Hazel and Applescript so I was stumped to get it to work. I posted something on the Hazel forums here. Alas no help for the noob. I resorted to running this as a folder action using Hazel to shuttle the files back and forth. It worked and I never got around to updating the system. Recently, someone visited the post and was looking for help to get it to work. So I dug back into the script to simplify it and use Hazel Applescript conventions.

The Details

So here's the script and a screen shot of how I have Hazel set up.

Screen Shot 2014-03-01 at 12.24.32 PM.png
-- this script adapted from post at solution by spazek
-- details on the use of this script for Hazel found a
-- Updated with delay to solve issue as described by Corwin Carr at Mac Power Users Show 186 notes
-- the First two commands avoid an error where Word would be unable to get the file path. The script would ultimately run appropriately, but only after throwing the error.

tell application "Microsoft Word" to activate
delay 1

tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path -- looks like we change the default path to where the document is and then set it back when we're done
tell application "Finder"
set theFilePath to container of theFile as text

set ext to name extension of theFile

set theName to name of theFile
copy length of theName to l
copy length of ext to exl

set n to l - exl - 1
copy characters 1 through n of theName as string to theFilename

set theFilename to theFilename & ".pdf"

tell application "Microsoft Word"
set default file path file path type documents path path theFilePath
open theFile
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name theFilename
close theActiveDoc
end tell

end tell

end try

tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath

end try