Scratching my head after reading lots of different threads on this and tried a bunch of scripts but none seem to work.
I'd like to use Automator to automate Word 2016 conversion of a selection of docx files to pdf.
Used the following Automator Service:
Used the following script:
on run {input, parameters}
tell application id "com.microsoft.Word"
activate
open input
set doc to name of active window
set theOutputPath to (input & ".pdf")
save as active document file name theOutputPath file format format PDF
end tell
end run
Which results in error: Microsoft Word got an error: active document doesn’t understand the “save as” message.
From the library panel on the left, select Files & Folders then double-click Get Specified Finder Items. Add the all the files to convert. From the library panel, now select Documents , then double click Convert Format of Word Documents. From the dropdown menu, select Portable Document Format (PDF)
Have the Word doc you want to convert to PDF open in Word for Mac. Go to the 'File' menu and choose “Export” Select “PDF” in the file format selection. Choose to Export the Word doc as a PDF.
Step 1: Open your Word file with Microsoft Office for Mac and then go to File> Save As. Step 2: Name the file in the “Save As” box and then from the “Format” drop down options, select PDF. Step 3: Click the “Save” button and your Word file will be turned into PDF in no time.
The main issue is that input
is a list. You have to use a repeat loop to process each file separately
I added a line to close the current document after having been converted
on run {input, parameters}
tell application id "com.microsoft.Word"
activate
repeat with aFile in input
open aFile
set theOutputPath to ((aFile as text) & ".pdf")
tell active document
save as it file name theOutputPath file format format PDF
close saving no
end tell
end repeat
end tell
end run
To prevent the problem discussed in @vadian's answer, save the file first to Word's default folder (that's usually ~/Library/Containers/com.microsoft.Word/Data/Documents) and then move the file somewhere else.
on run {input, parameters}
repeat with aFile in input
tell application "System Events"
set inputFile to disk item (aFile as text)
set outputFileName to (((name of inputFile) as text) & ".pdf")
end tell
tell application id "com.microsoft.Word"
activate
open aFile
tell active document
save as it file name outputFileName file format format PDF
close saving no
end tell
set defaultPath to get default file path file path type documents path
end tell
tell application "System Events"
set outputPath to (container of inputFile)
set outputFile to disk item outputFileName of folder defaultPath
move outputFile to outputPath
end tell
end repeat
return input
end run
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With