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

how do I use automator to batch convert doc to pdf?

Although I thought it would be an easy thing to do I'm finding it difficult to get much info or help on this. The few scripts and instructions I have discovered on the web don't seem to work. I tried to create one with a get file and then convert word docx. It creates the pdfs but they are corrupted and can't be opened.


Any ideas anyone?

Macpro, Mac OS X (10.6.4)

Posted on May 11, 2011 12:06 AM

Reply
90 replies

Mar 2, 2017 9:21 PM in response to spazek

Am looking to be able to convert a large number of google doc documents to .pdf and this looks to be what I am looking for. However, I copy and paste the code into Automator and try to compile, but the compiler chokes on the following line:

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

and provides the following error

User uploaded file

and it highlights the BOLDED 'file'


Any ideas as to what the problem is?


Any help is appreciated.

May 11, 2011 12:14 PM in response to zalamander

Hi!

The Convert Format Of Word Documents Action will not work correctly with Office 2011.


Use instead the Run AppleScript Action:


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


on run {input, parameters}

set output to {}

tell application "Microsoft Word" to set theOldDefaultPath to get default file pathfile path typedocuments 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 pathfile path typedocuments pathpaththeFilePath

open theDoc

set theActiveDoc to the active document


save astheActiveDocfile formatformat PDFfile nametheFilename

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" to set default file pathfile path typedocuments pathpaththeOldDefaultPath



return output

end run


This AppleScript will convert any doc or docx documents to PDF and save them in the same folder as the original. The output of the action will be the path to the new PDF files. So just say you want to move them to a certain folder add the Move Finder Items Action.


May 12, 2011 11:06 AM in response to Stress Test

Again, sorry for being an idiot but how do you do that? I found the action run apple script and pasted your code where it says to (I selected the (* your script goes here *) and pasted over it. When I press the play button it says "unexpected end but found property".


I've never used automator or scripts and have no idea of programming. Could you please give a bit more detail?

May 12, 2011 3:22 PM in response to zalamander

A workflow containing only that Run AppleScript action and saved as an application will work as a droplet.

Drag and drop the files on the application.



To make it work with double-clicking it you need to add at least one more action and put it in front, like

Ask for Finder Items or Get selected Finder Items and more.

- - - - - - - - - - -


To show you the possibilities of Automator.

Open Automator.

Choose template Service

check: Service receives selected files and folders in Finder.app

Set the actions:


• Get Folder content

• Run AppleScript (and paste the script there)


Save the workflow.


Now select the .doc/docx files in Finder OR the folder containing these files.

Right-click the files/folder and look for the service in the contextual menu.

Choose (run) the service

May 29, 2011 5:25 PM in response to spazek

hi Spazek and Zalamander,


Can one of you explain a little more about how to get Spazek's script to work in Automator?


I did the same thing at first as Zalamander. I pasted the script replacing the line (* Your script goes here *) but leaving the preceding and following lines. When I try to run it in Automator, I get the error "Syntax Error Expected "end" and found "property" and the word "properties" in the first line of the pasted script is highlighted.In Automator the "run applescript" action is prefilled with this text.


<code>

on run {input, parameters}


(* Your script goes here *)


return input

end run


</code>



However, if I replace the entire action with the script or if I try running or compling only the script in Applescript, it tells me there's a "Syntax Error Expected end of line, etc, but found identifier." and the word "PDF" is highlighted in this line

save as theActiveDoc file format format PDF file name theFilename


This sounds like a great Automator service or Droplet to have. I was looking for something like it the other day and saw this thread by accident in the recent thread list.


Message was edited by: Marlinespike

how do I use automator to batch convert doc to pdf?

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