Thursday, October 6, 2022

#1 2015-05-26 08:37:01 pm

MacNewbie
Member
Registered: 2015-05-26
Posts: 3

PDF to Word

Hello, I am new to using Applescript and I am having some trouble writing a script to save a pdf as a word document in Adobe Acrobat Pro. The script I wrote so far finds the document and opens it.  However, the apple script does not appear to recognize click action and I am not sure how to complete the  apple script. Any suggestions?


tell application "Finder"
    activate
    open document file "Test Word.pdf" of folder "PDF to DOC" of folder "Desktop" of folder "jack" of folder "Users" of startup disk
   
end tell
tell application "Adobe Acrobat Pro"
    tell application "System Events"
        tell process "Adobe Acrobat Pro"
            tell menu bar 1
                tell menu "File"
                    tell menu item "Save As"
                    Click "Microsoft Document"
                                        Click "Word Document"
                                     end tell
                end tell
            end tell
        end tell
    end tell
end tell


Filed under: applescript, PDF to Word

Offline

 

#2 2015-05-26 10:46:38 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11776
Website

Re: PDF to Word

Hi,

try this

Applescript:


set PDFDoc to (path to desktop as text) & "PDF to DOC:Test Word.pdf"
tell application "Adobe Acrobat Pro"
   activate
   open PDFDoc
end tell
tell application "System Events"
   tell process "AdobeAcrobat"
       click menu item "Word Document" of menu 1 of menu item "Microsoft Word" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
       repeat until exists window "Save As"
           delay 0.2
       end repeat
       click button "Save" of window "Save As"
   end tell
end tell


regards

Stefan

Offline

 

#3 2015-05-27 06:26:05 am

MacNewbie
Member
Registered: 2015-05-26
Posts: 3

Re: PDF to Word

Worked great! Thank you!

Offline

 

#4 2022-06-11 08:51:46 pm

donnyh
Member
Registered: 2009-03-18
Posts: 32

Re: PDF to Word

@StefanK, how would one modify this (I'm using the version of Acrobat in the script) to open a folder of pdfs and convert them to .docx? Is it possible to also request a folder to save to?

Offline

 

#5 2022-06-11 09:30:19 pm

donnyh
Member
Registered: 2009-03-18
Posts: 32

Re: PDF to Word

I have this from trying to combine two scripts here, but it won't compile. What am I doing wrong?

Applescript:

property Default_Location : (path to desktop as Unicode text) as alias
--
set Input_Folder to choose folder default location Default_Location with prompt "Select a folder of PDFs" without invisibles
--
tell application "Finder"
   -- Check to see if your folder is on the desktop else make one
   if not (exists (folder "pdf to docx" of Default_Location)) then
       make new folder at Default_Location with properties {name:"pdf to docx"}
   end if
   set Output_Folder to (folder "pdf to docx" of Default_Location) as text
   --
   set File_List to (files of Input_Folder whose name extension is "pdf")
   repeat with This_File in File_List
       set The_File to This_File as alias
       tell application "Adobe Acrobat Pro"
           activate
           open The_File
           set Doc_Name to name of document 1
           set Base_Name to my getBaseName(Doc_Name)
           set New_File_Path to Output_Folder & Base_Name & ".docx"
           end tell
           tell application "System Events"
   tell process "Acrobat"
       click menu item "Word Document" of menu 1 of menu item "Microsoft Word" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
       repeat until exists window "Save As"
           delay 0.2
       end repeat
       click button "Save" of window "Save As"
   end tell
end tell

Last edited by donnyh (2022-06-11 09:31:31 pm)

Offline

 

#6 2022-06-12 08:51:16 am

robertfern
Member
Registered: 2011-11-29
Posts: 202

Re: PDF to Word

You were missing two end statements.

One for a repeat loop and one for a tell statement.

Applescript:


property Default_Location : (path to desktop as Unicode text) as alias
--
set Input_Folder to choose folder default location Default_Location with prompt "Select a folder of PDFs" without invisibles
--
tell application "Finder"
   -- Check to see if your folder is on the desktop else make one
   if not (exists (folder "pdf to docx" of Default_Location)) then
       make new folder at Default_Location with properties {name:"pdf to docx"}
   end if
   set Output_Folder to (folder "pdf to docx" of Default_Location) as text
   --
   set File_List to (files of Input_Folder whose name extension is "pdf")
   repeat with This_File in File_List
       set The_File to This_File as alias
       tell application "Adobe Acrobat Pro"
           activate
           open The_File
           set Doc_Name to name of document 1
           set Base_Name to my getBaseName(Doc_Name)
           set New_File_Path to Output_Folder & Base_Name & ".docx"
       end tell
       tell application "System Events"
           tell process "Acrobat"
               click menu item "Word Document" of menu 1 of menu item "Microsoft Word" of menu 1 of menu item "Save As" of menu 1 of menu bar item "File" of menu bar 1
               repeat until exists window "Save As"
                   delay 0.2
               end repeat
               click button "Save" of window "Save As"
           end tell -- was missing
       end tell
   end repeat -- was missing
end tell

Last edited by robertfern (2022-06-12 08:52:31 am)

Offline

 

#7 2022-06-12 09:35:19 am

donnyh
Member
Registered: 2009-03-18
Posts: 32

Re: PDF to Word

@robertfern thanks! That did allow the script to compile. Thanks for your help.

New problem: When the script is running it's creating a new script on the desktop called pdf to wordx as opposed to going to that folder. Additionally, after opening a couple of the files in Acrobat Pro, it stops with an error "«script» doesn’t understand the “getBaseName” message" from the line "set Base_Name to my getBaseName(Doc_Name)"

Can you help with that? Really appreciate you.

Offline

 

#8 2022-06-12 11:25:35 am

robertfern
Member
Registered: 2011-11-29
Posts: 202

Re: PDF to Word

I can't help due to I don't have Acrobet Pro

Offline

 

#9 2022-06-12 02:57:27 pm

donnyh
Member
Registered: 2009-03-18
Posts: 32

Re: PDF to Word

Thanks, @robertfern.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)