You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Batch Convert Word Docs to PDF

I'd like to create an Automator workflow to batch convert Word documents to PDF. I found a discussion about it from 2011 here that included a couple of Applescripts to use via Automator, but both of the scripts throw errors when I try to use them in Automator.


Unfortunately Applescripting is not my forte; would anyone be willing to take a look at the scripts here, or maybe have one of your own that works?


Thank you!

MacBook Pro 13″, macOS 10.15

Posted on Jul 17, 2020 11:17 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 18, 2020 8:11 AM

Copying the script from those old posts has a lot of errors due to the site running strings together.

This version should work correctly when copied/pasted. I modified it slightly to tell word to Quit when done and removed the return which wasn't necessary.

If you don't want Word to quit, remove the "Quit" near the end of the script.

property theList : {"doc", "docx"}

on run {input, parameters}
	tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
	repeat with x in input
		try
			set theDoc to contents of x
			tell application "Finder"
				set theFilePath to container of theDoc as text
				
				set ext to name extension of theDoc
				if ext is in theList then
					set theName to name of theDoc
					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 theDoc
						set theActiveDoc to the active document
						
						save as theActiveDoc file format format PDF file name theFilename
						copy (POSIX path of (theFilePath & theFilename as string)) to end of output
						
						closetheActiveDoc
					end tell
				end if
			end tell
		end try
	end repeat
	tell application "Microsoft Word"
		set default file path file path type documents path path theOldDefaultPath
		quit
	end tell
end run


The entire script here replaces everything in the Run AppleScript Action in Automator.

I used an Application so I could drop files onto the App.


Might be best to add a Filter Finder Items to the top of the workflow to filter for docx and doc file types.

Similar questions

6 replies
Question marked as Top-ranking reply

Jul 18, 2020 8:11 AM in response to TomRinOK

Copying the script from those old posts has a lot of errors due to the site running strings together.

This version should work correctly when copied/pasted. I modified it slightly to tell word to Quit when done and removed the return which wasn't necessary.

If you don't want Word to quit, remove the "Quit" near the end of the script.

property theList : {"doc", "docx"}

on run {input, parameters}
	tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
	repeat with x in input
		try
			set theDoc to contents of x
			tell application "Finder"
				set theFilePath to container of theDoc as text
				
				set ext to name extension of theDoc
				if ext is in theList then
					set theName to name of theDoc
					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 theDoc
						set theActiveDoc to the active document
						
						save as theActiveDoc file format format PDF file name theFilename
						copy (POSIX path of (theFilePath & theFilename as string)) to end of output
						
						closetheActiveDoc
					end tell
				end if
			end tell
		end try
	end repeat
	tell application "Microsoft Word"
		set default file path file path type documents path path theOldDefaultPath
		quit
	end tell
end run


The entire script here replaces everything in the Run AppleScript Action in Automator.

I used an Application so I could drop files onto the App.


Might be best to add a Filter Finder Items to the top of the workflow to filter for docx and doc file types.

Jul 18, 2020 8:10 AM in response to Barney-15E

If the OP is actually on Catalina, then nine-year old AppleScript syntax that was developed (probably) for MS Word 2011 AppleScript dictionary compatibility — may have changed in present Microsoft 365 or Office 2019 for Mac Scripting Dictionary syntax. Let's hope it hasn't.


I also have a shell script that uses LibreOffice to convert Word documents to PDF, if the OP needs it.

Batch Convert Word Docs to PDF

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.