1 2 3 Previous Next 77 Replies Latest reply: Jun 30, 2014 10:34 PM by Eureka098
zalamander Level 1 Level 1 (15 points)

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)
  • 1. Re: how do I use automator to batch convert doc to pdf?
    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.

  • 2. Re: how do I use automator to batch convert doc to pdf?
    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.

     


  • 3. Re: how do I use automator to batch convert doc to pdf?
    zalamander Level 1 Level 1 (15 points)

    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

  • 4. Re: how do I use automator to batch convert doc to pdf?
    Stress Test Level 4 Level 4 (1,265 points)

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

  • 5. Re: how do I use automator to batch convert doc to pdf?
    zalamander Level 1 Level 1 (15 points)

    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?

  • 6. Re: how do I use automator to batch convert doc to pdf?
    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

  • 7. Re: how do I use automator to batch convert doc to pdf?
    zalamander Level 1 Level 1 (15 points)

    ok thanks I think it works now (?) I ran it and it gave me some green ticks. Now how do I use it? I tried saving it as an application but when I double click it nothing happens.

  • 8. Re: how do I use automator to batch convert doc to pdf?
    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

  • 9. Re: how do I use automator to batch convert doc to pdf?
    zalamander Level 1 Level 1 (15 points)

    hey thanks a lot! it worked perfectly when I put the ask for finder items in front like you said.

     

    The app works great and is sitting in my dock

  • 10. Re: how do I use automator to batch convert doc to pdf?
    Rod Christiansen Level 1 Level 1 (5 points)

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

    Thanks!

  • 11. Re: how do I use automator to batch convert doc to pdf?
    Marlinespike Level 4 Level 4 (1,880 points)

    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

  • 12. Re: how do I use automator to batch convert doc to pdf?
    Rod Christiansen Level 1 Level 1 (5 points)

    This is how mine worked: http://cl.ly/2f1V2a030e1W2d201w0v

  • 13. Re: how do I use automator to batch convert doc to pdf?
    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.

  • 14. Re: how do I use automator to batch convert doc to pdf?
    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 Previous Next