Skip navigation

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

43476 Views 57 Replies Latest reply: Mar 20, 2014 7:47 PM by SkyWatching RSS
1 2 3 4 Previous Next
zalamander Level 1 Level 1 (15 points)
Currently Being Moderated
May 11, 2011 12:06 AM

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)
  • Stress Test Level 4 Level 4 (1,265 points)

    Same here on Word 2011. An error occurs when using the word action Somethings wrong with the word automator action, maybe there will be an update.

  • spazek Level 2 Level 2 (215 points)

    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 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

      close theActiveDoc

                                                      end tell

                                            end if

                                  end tell

                        end try

              end repeat

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

     

     

              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.

     


    MBP / Mac Pro, Mac OS X (10.6.7), please excuse my bad english
  • Stress Test Level 4 Level 4 (1,265 points)

    Have you put the code in Automator into the action "Run AppleScript"?

  • spazek Level 2 Level 2 (215 points)

    Hi zalamander!

     

    Sorry. I had to explain it better how to use the script:

    Replace the entire text of the Run AppleScript Action with the posted script.

     

    Spazek

  • spazek Level 2 Level 2 (215 points)

    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

    MBP / Mac Pro, Mac OS X (10.6.7), please excuse my bad english
  • Rod Christiansen Level 1 Level 1 (5 points)
    Currently Being Moderated
    May 29, 2011 2:57 PM (in response to spazek)

    This works great!! Do you have an AppleScript that does the same thing for PowerPoint docs? From .ppt to .pdf?

    Thanks!

  • Marlinespike Level 4 Level 4 (1,880 points)
    Currently Being Moderated
    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

    MBP 13 2.53gHZ/4mb RAM, PB G4 12, 1gHZ/768 mb RAM, OS X.3.9, Mac OS X (10.6.7), Touch 2 gen, Shuffle 1 gen, Nano 2 gen, PM7300/200 416 mb RAM OS
  • Rod Christiansen Level 1 Level 1 (5 points)
  • Marlinespike Level 4 Level 4 (1,880 points)

    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.

  • spazek Level 2 Level 2 (215 points)

    @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" using command 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

      close theActiveDoc

      end tell

      end repeat

      return input

    end run

     


1 2 3 4 Previous Next

Actions

More Like This

  • Retrieving data ...

Bookmarked By (6)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.