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

Question:

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

Reply
Question marked as Solved
Answer:
Answer:

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

Posted on

Page content loaded

May 11, 2011 12:14 PM in response to zalamander 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 11, 2011 12:14 PM

Reply Helpful (2)

May 12, 2011 9:03 AM in response to spazek In response to spazek

Thanks


I copied and pasted your script into the editor and saved it as an app but when I run it I get a msg:

current application doesn't match the parameters {input, parameter} for run.


Sorry if I look an idiot but I know nothing about scripts and programming - can you tell me what I'm doing wrong?


Thanks

May 12, 2011 9:03 AM

Reply Helpful

May 12, 2011 11:06 AM in response to Stress Test 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 11:06 AM

Reply Helpful
Question marked as Solved

May 12, 2011 3:22 PM in response to zalamander 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 12, 2011 3:22 PM

Reply Helpful

May 29, 2011 5:25 PM in response to spazek 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

May 29, 2011 5:25 PM

Reply Helpful

May 30, 2011 6:10 AM in response to Rod Christiansen In response to Rod Christiansen

Thanks, the first part of the automator runs, it's the Applescript part that gets hung up with this error "Syntax Error Expected end of line, etc, but found identifier."


I"m also wondering now if this would work with Word 2004.

May 30, 2011 6:10 AM

Reply Helpful

May 30, 2011 3:32 PM in response to Marlinespike In response to Marlinespike

@Marlinespike & @RodChristiansen:


Sorry, there is no "save as file format format PDF" command in Word 2004`s and PowerPoint`s AppleScript dictionary ....



You could try to realize it via so called "GUI Scripting"

I really do not like GUI Scripting 😐 ... but i hope this script will work for you:

(You enable GUI Scripting by enabling access for assistive devices in the Universal Access System Preferences panel -- but the first lines in the AppleScript will do this for you too)



this will work with one or more files.

Running it as a Service (as RodChristiansen showed) is a good idea.



on run {input, parameters}


--ENABLE GUI SCRIPTING

tell application "System Events"

if UI elements enabled is false then set UI elements enabled to true

end tell


--RUN THE GUISCRIPT

set pdfSavePath to POSIX path of (choose folder with prompt "Set destination folder")

repeat with x in input


tell application "Microsoft Word"


activate

open x

set theActiveDoc to the active document


tell application "System Events"

tell process "Microsoft Word"


keystroke "p" usingcommand down

repeat until exists window "Print"

end repeat

click menu button "PDF" of window "Print"

repeat until exists menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"

end repeat

click menu item "Save as PDF…" of menu 1 of menu button "PDF" of window "Print"

repeat until exists window "Save"

end repeat


keystroke "g" using {command down, shift down}

set value of text field 1 of sheet of window "Save" to pdfSavePath

click button "Go" of sheet of window "Save"

click button "Save" of window "Save"

end tell

end tell


closetheActiveDoc

end tell

end repeat

return input

end run


May 30, 2011 3:32 PM

Reply Helpful
User profile for user: zalamander

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