Solved: Options in automating batch conversion of Word.doc to PDFs

Hey Neal,

First let's clean up that script just a little.

--------------------------------------------------------------------------------
# Task: A Droplet to Convert Word Documents to .PDF format.
# dMod: 2016/07/05 22:00
--------------------------------------------------------------------------------
on open theFileList
   
   tell application id "com.microsoft.Word"
      set oldDefaultPath to get default file path file path type documents path
   end tell
   
   repeat with theFile in theFileList
      
      tell application "Finder"
         set theFileParentPath to theFile's container as text
         set theFileName to get theFile's name
         set theFileNameExtension to theFile's name extension
      end tell
      
      set AppleScript's text item delimiters to ("." & theFileNameExtension)
      set newFileName to (text item 1 of theFileName) & ".pdf"
      
      tell application id "com.microsoft.Word"
         set default file path file path type documents path path theFileParentPath
         open theFile
         
         tell active document
            save as file format format PDF file name newFileName
            close
         end tell
         
      end tell
      
   end repeat
   
   tell application id "com.microsoft.Word"
      set default file path file path type documents path path oldDefaultPath
   end tell
   
end open
--------------------------------------------------------------------------------

NOTE: I've change the hard-coded path to Word's bundle id:

application id "com.microsoft.Word"

Neal – this may work for you – but I don't have PC-Word in a virtual machine to test with.

Try running this from the Script Editor.app to find out:

tell application id "com.microsoft.Word"
   path to it
end tell

Next let's provide a downloadable droplet:

Word Document to .PDF Converter v1.01.zip (63.4 KB)

NOTE: This can be opened using the Script Editor.app.

Finally – since I really dislike using droplets – here's how to run the droplet on the selection in the Finder:

--------------------------------------------------------------------------------
set theDroplet to "~/test_directory/KM_TEST/Word Document to .PDF Converter.app"
tell application "System Events"
   set theDroplet to (POSIX path of disk item theDroplet) as «class furl»
end tell

tell application "Finder"
   set finderSelectionList to selection as alias list
   if length of finderSelectionList = 0 then error "No files were selected in the Finder!"
   open finderSelectionList using application file theDroplet
end tell
--------------------------------------------------------------------------------

One advantage of using a droplet this way is the job is handed-off to the droplet application – Keyboard Maestro is relieved of the load and will be somewhat more responsive to other tasks.

-Chris

4 Likes