Access a drop down list

Trying to write routine for Quickbooks that will select a PDF option rather than print the result of previous commands. I am reconciling credit card and bank accounts. One a reconciliation is completed I want to save the result to a pdf file rather than printing it.

The following script starts after the reconciliation has been completed, it produces drop down sheet from which various selections can be made. The one I want to use is drop down box , the command

“click menu button “PDF” of sheet 1 of window “Reconciliation Summary””

opens the drop down box and that is where I am stuck.

I have tried a number of variations of the last line

" click item 2 of menu button “PDF” of sheet 1 of window “Reconciliation Summary”"

Item 2 is the correct location in the drop down for save as a PDF

this is the script and suggestions very much appreciated .

tell application "QuickBooks 2019"
	activate
	tell application "System Events" to tell process "QuickBooks 2019"
		tell application "QuickBooks 2019" to activate window "Reconciliation Summary"
		click button 9 of toolbar 1 of window "Reconciliation Summary"
		click checkbox "Shrink report to fit page width" of tab group 1 of sheet 1 of window "Reconciliation Summary"
		click menu button "PDF" of sheet 1 of window "Reconciliation Summary"
		delay 2
		click item 2 of menu button "PDF" of sheet 1 of window "Reconciliation Summary"
		
	end tell
end tell

I don’t have Quickbooks, so I can’t look at it in context.

UI scripting, in my experience, is frequently tricky to get right.

Do you have UI Browser, Accessibility Inspector (comes with Xcode), or Script Debugger? Any of these can help you inspect what’s actually there instead go flying blind/guessing. Script Editor can too sometimes, it’s just more of a PITA.

The first thing I suspect is that once you click “menu button “PDF””, the drop-down menu isn’t called that anymore… clicking it opens a new UI element whose name you need to know to address it.

I’d try one of the three above mentioned apps if you have them, or with Script Editor, try something like:

[AppleScript]
tell application “System Events” to tell process “QuickBooks 2019”
tell application “QuickBooks 2019” to activate window “Reconciliation Summary”
click button 9 of toolbar 1 of window “Reconciliation Summary”
click checkbox “Shrink report to fit page width” of tab group 1 of sheet 1 of window “Reconciliation Summary”
click menu button “PDF” of sheet 1 of window “Reconciliation Summary”
set allUIelements to every UI element of sheet 1 of window “Reconciliation Summary”
end tell
return allUIelements
[/AppleScript]

See what you get there… may be something else to target. If you see anything that sounds likely but need to get subelements of it, modify the script accordingly and run it again.

I’ve also had a weird instance where “click [UI element blah blah]” didn’t work, but

“tell UI element bah blah
click it
end tell”

did. No idea why, but if you’re sure you’ve got your terminology for the UI element correct, might be worth a shot.

Thank you very much, I do have and use Script Debugger that’s how I managed to get as far as I have.

I will try your suggestion to see what all the elements are. One thing I did not mention in my first post is that if I step through the routine the drop down box appears when it reaches

click menu button “PDF” of sheet 1 of window “Reconciliation Summary”

but it immediately closes.

Your idea makes sense and I will try that let you know the result.

Tried your suggestions no luck with putting it in a tell block. Printed out all the UI element’s and the starting point is definitely "menu button “PDF”.

The issue I mentioned in my last post is that when I step through the code it opens the drop down box but for second, it just does not stay open which I guess is the reason it does not get reported with your allUIelements.

Interestingly using your suggestion of a tell block with a delay command after “click it” kept the drop down box visible whereas just clicking it without the tell block did not. Could it be that I need a different command for a drop down box.

The fact that the drop down box closes before I can issue another command is the root of the issue.

Once again many thanks.

Sorry, it’s hard for me (and everyone else here who might have taken a look at this) to investigate without the program installed.

If you get the attributes of “menu button PDF,” does it have anything more promising than just using “click?” I don’t know that much about cocoa UI - I’m wondering if there’s a property like “expanded” or something that you could address, rather than just a click. Or if it’s possible to address it’s sub-elements in any way without actually expanding it in the GUI.

Hey, are you trying to click “Save as PDF” from a standard Apple print dialog, or is this something specific to Quickbooks UI?

Try something like this:


tell application "QuickBooks 2019"
	activate
	tell application "System Events" to tell process "QuickBooks 2019"
		tell application "QuickBooks 2019" to activate window "Reconciliation Summary"
		click button 9 of toolbar 1 of window "Reconciliation Summary"
		click checkbox "Shrink report to fit page width" of tab group 1 of sheet 1 of window "Reconciliation Summary"
		repeat until exists sheet 1 of window "Reconciliation Summary"
		tell sheet 1 of window "Reconciliation Summary"
			click menu button "PDF"
			repeat until exists menu item "Save as PDF" of menu 1 of menu button "PDF"
			end repeat
			click menu item "Save as PDF" of menu 1 of menu button "PDF"
		end tell
	end tell
end tell

My apologies for the delay in replying to your suggestions. Understand the difficulty when you do not have the program in question. The answer to your question is that it is a QB command.

Having a little trouble getting your latest suggestion to compile will let you know the result when I sort out what I am doing incorrectly.

Peter

Sorted out the compile issue . Took out the 1st repeat loop as that caused it to exit and it worked. Its mystery to me, I added a counter to your repeat block and the log of the result is 0. So I removed the repeat block and it worked. Got me but cannot thank you enough, for what its worth this is the final routine.

tell application "QuickBooks 2019"
	activate
	tell application "System Events" to tell process "QuickBooks 2019"
		tell application "QuickBooks 2019" to activate window "Reconciliation Summary"
		click checkbox "Shrink report to fit page width" of tab group 1 of sheet 1 of window "Reconciliation Summary"
		click button 9 of toolbar 1 of window "Reconciliation Summary"
		tell sheet 1 of window "Reconciliation Summary"
			click menu button "PDF"
			click menu item "Save as PDF" of menu 1 of menu button "PDF"
		end tell
	end tell
end tell

That’s great you got it working. Glad my input was of use.

Maybe I just don’t understand it well enough, but in my experience UI scripting is sometimes as much voodoo magic guesswork as actual programming. It’s googling something someone else found that works, but even when you see a working solution, it doesn’t really make sense why it worked and whatever else you’ve tried doesn’t.