Tuesday, June 18, 2019

#1 2019-02-11 11:19:25 am

MitchBVI
Member
Registered: 2006-02-14
Posts: 139

Cannot Select Button on Drop Down sheet

I am automating a process in PDFPenPro the object is to split a PDF file into a single or multiple sheets save it with a new name and location. I have run into a problem, as the files I am working on are all scanned when the new file opens a drop down sheet opens and the options are "Cancel", "OCR Page" and "OCR Document", the default selection is "OCR Document".I cannot manually select the Cancel option without building in a time delay which I have done but it would be easier if I could just code to select the cancel button.  I have written a small script which works in returning the name of the button I want to select but when I try and use the same sequence to click it I get a message that it is an invalid index. So it works for the name not the click option any suggestions greatly appreciated. In the script below I passed the name to a variable "test" to make sure it was actually getting the correct name. The following do not work the 1st returns incorrect index, the second cannot get Process "PDFPenPro", and the last does not understand the click message.

Click button 2 of sheet I of window 1
Click button 2 of sheet I of window 1 of Process "PDFPenPro"
Click button 2 of sheet I of window 1 of Application "PDFPenPro"

Applescript:


tell application "PDFpenPro"
   activate
   tell application "System Events"
       get name of button 2 of sheet 1 of window 1 of process "PDFpenPro"
       set test to name of button 2 of sheet 1 of window 1 of process "PDFpenPro"
       display dialog test
   end tell
end tell

Model: MacBook Pro
AppleScript: 2.10
Browser: Safari 12
Operating System: macOS 10.14

Offline

 

#2 2019-02-11 11:44:26 am

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

Re: Cannot Select Button on Drop Down sheet

In GUI scripts the most reliable way is a controlled delay which waits until a particular UI element appears/exists.

Applescript:

activate application "PDFpenPro"
tell application "System Events"
   tell process "PDFpenPro"
       repeat until exists sheet 1 of window 1
           delay 0.25
       end repeat
       click button 2 of sheet 1 of window 1
   end tell
end tell

Last edited by StefanK (2019-02-11 11:44:48 am)


regards

Stefan

Offline

 

#3 2019-02-11 03:14:31 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 139

Re: Cannot Select Button on Drop Down sheet

Hi thanks very much for getting back to me I had thought it may have been a delay problem but that had not worked. Turns out I had my script the wrong way round I needed the process not the application inside of the systems tell block. This finally worked.

Applescript:


activate application "PDFpenPro"
tell application "System Events"
   tell process "PDFpenPro"
       click button 2 of sheet 1 of window 1
   end tell
end tell

I need to figure out the correct use of process. I had tried putting  a tell PDFPenPro inside of the  tell systems events but that simple switched the focus and the click command did not work.

Thanks again

Peter

Offline

 

#4 2019-02-11 05:13:58 pm

MitchBVI
Member
Registered: 2006-02-14
Posts: 139

Re: Cannot Select Button on Drop Down sheet

Hi Stephan

I spoke far to soon you and you may not be able to help as my problem may well be in PDFPenPro. I found that when my code was built into the body of my scrip it did not work. So I paid attention to what you said and added the delay. That worked when I ran it from script editor but simple hangs when I run it from PDFPenPro. You may not know but PDFPenPro provide a number of scrips as part of their program and one can add additions which I have done this being one of them.

Applescript:




display dialog "This script breaks up PDF files with Multipe JIBs or Deposits. To save having to select the destination folder every time make sure that the current finder window is the appropriate one. Exit this script" with icon note buttons {"Exit", "Continue"} default button "Continue"
if the button returned of the result is "Exit" then
   return
end if
display dialog "This script assumes the pages to be used to create a new PDF have been selected in the side bar if not Exit this script and run it again when selection is made" buttons {"Exit", "Continue"} default button "Continue"
if the button returned of the result is "Exit" then
   return
end if
tell application "PDFpenPro"
   activate
   tell application "System Events"
       key code 45 using {shift down, command down} --This opens the selected page(s) of the PDF as a new PDF    
       tell process "PDFpenPro"
           repeat until exists sheet 1 of window 1
               delay 0.25
           end repeat
           click button 2 of sheet 1 of window 1
       end tell
   end tell
end tell


tell application "PDFpenPro"
   activate
   
   set frontwin to name of front window of application "PDFpenPro"
   display dialog "Name of this file is " & frontwin & " Change it" buttons {"Yes", "No"} default button "Yes"
   if button returned of result = "YES" then
       display dialog "Enter Name of file" default answer ""
       set frontwin to text returned of result & ".pdf"
       set name of front window of application "PDFpenPro" to frontwin
   end if
   tell application "Finder"
       if exists Finder window 1 then
           set currentDir to target of Finder window 1 as alias
       end if
   end tell
   
   --############ For Testing
   display dialog "Save File; Note for testing Only" buttons {"Yes", "No"} default button "No"
   if button returned of result = "NO" then return
   --###########
   
   display dialog "Current path to Save this file is " & currentDir & " Change it" buttons {"yes", "No"} default button "No"
   if button returned of result = "NO" then
       set saveto to currentDir
   else
       set saveto to choose folder with prompt "Select File Location:"
   end if
   set saveto to saveto & frontwin as string
   save document 1 in file saveto
   close document 1 saving no
end tell

Thanks again

Peter

Offline

 

#5 2019-02-12 11:01:36 am

MitchBVI
Member
Registered: 2006-02-14
Posts: 139

Re: Cannot Select Button on Drop Down sheet

Hi Stefan

Sorry for misspelling you name in last post.

Quick up date, I added my script to the Scripts accessible from the icon on the menu bar and it works  with your revision so it looks like a PDFPENpro issue.

Thanks

Peter

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)