What's the best way to access this menu in the Numbers Print Dialog?

Hi, Gang.

I'm trying to improve a working macro which uses found image clicking and keystrokes to create a PDF of the current sheet and open it in Preview. To allow this, the Numbers print dialog has a handy menu of PDF-related action at the the bottom.

I can successfully click the right-hand portion (down arrow) to expose the dropdown menu...

Numbers Print Dialog PDF Dropdown Menu

...and select the "Open in Preview" option from there with "Click at Found Image" actions, however I'm wondering if there's another way to get that to happen.

The "Press Button" action presses the "PDF" portion of the button (I guess they are two separate buttons), bringing up a save dialog. For reasons I won't get into, I'd prefer to open it directly in Preview. Anyone have an idea?

Here's a shot of the relevant step in the Macro:

Cheers, Everyone!

Howdy, welcome to the forum!

Once you have that print dialog open, the following AppleScript should do the trick (I’m on Ventura, so if you’re on a different OS, there’s a possibility that menu item differences will cause it to fail).

AppleScript to open in preview (click to expand/collapse)
tell application "System Events"
	tell application process "Numbers"
		click menu button 1 of group 2 of splitter group 1 of sheet 1 of window 1
		repeat until exists menu item 1 of menu 1 of group 2 of splitter group 1 of sheet 1 of window 1
			delay 0.1
		end repeat
		click menu item 1 of menu 1 of group 2 of splitter group 1 of sheet 1 of window 1
	end tell
end tell

Technically, you can replace your entire macro with AppleScript...

AppleScript full replacement (click to expand/collapse)
tell application "System Events"
	tell application process "Numbers"
		
		# click print without preview menu item
		click menu item "Print Without Preview…" of menu 1 of menu bar item "File" of menu bar 1
		
		# wait for the PDF dropdown arrow to appear
		repeat until exists menu button 1 of group 2 of splitter group 1 of sheet 1 of window 1
			delay 0.1
		end repeat
		
		# click the PDF dropdown arrow
		click menu button 1 of group 2 of splitter group 1 of sheet 1 of window 1
		
		# wait for the Open in Preview option to appear
		repeat until exists menu item 1 of menu 1 of group 2 of splitter group 1 of sheet 1 of window 1
			delay 0.1
		end repeat
		
		# click the Open in Preview option
		click menu item 1 of menu 1 of group 2 of splitter group 1 of sheet 1 of window 1
		
	end tell
end tell

If you have questions about either one of those scripts, or how to implement/use them, just let me know and I’d be happy to help further.

Chris

I don't even know what techniques you use to figure that out. I'm guessing the Script Editor, but can you tell us what your approach was? I'd like to learn.

This works beautifully! Many thanks! Like @Airy, I would also like to know how you figure that out. What tools are you using to get the paths to the items?

To get an idea, here a couple of (hopefully) useful topics/posts:

Also: Search results for 'applescript ui scripting'

1 Like

Alright. I'm now trying to click this:

Using UI Browser and Accessibility Inspector, I've managed to sniff out this bit of AppleScript which worked once or twice and then didn't:

select text field 3 of sheet 1 of window "Hendrix - XXXXX Invoice.numbers-Invoice.pdf – 1 page" 

My goal, if it's even possible is to figure out how to refer to this element (the Save dialog search field) without the unique reference of the window name. (The hideous file name is a result of the PDF export from Numbers and gets sorted out in the save process with some find and replace actions.)

This way gets the desired text into the search field, but the search get stuck and won't complete even with manual assistance:

set value of text field 3 of sheet 1 of window "Hendrix - XXXXX Invoice.numbers-Invoice.pdf – 1 page"  to "<string>"

This doesn't appear to work either:

		tell application "System Events"
			tell its application process "Preview"
				tell its window "Hendrix - XXXXX Invoice.numbers-Invoice.pdf – 1 page"
					tell its sheet 1
						tell its text field 3
							tell its UI element 1
								action "AXPress"
							end tell
						end tell
					end tell
				end tell
			end tell
		end tell

Ideas?

Thanks to KM11, we no longer need AppleScript to press dialog buttons.

This will Open in Preview:

This can be helpful when trying to script for UI interaction:

Assuming the inital state is that the Save As: field is focused, you can tab to the Search field:

2 Likes

Nice! Had to add a 0.5s pause after the Return keystroke to get it working in the macro. Playing around with the Press Button action was very instructive. Thanks!

I'll be using your UI Browser Lite macro on a daily basis. Thanks for that, too.

To perform the search I have this, which works:

I was just looking for a more direct way to do it if such a thing was possible.

1 Like

I understand. AppleScript can be comparatively laborious to setup and slow to execute when compared to KM actions (depending on the context).

You may also find that a 0.2s pause will suffice. If the 0.5s one doesn't feel too sluggish to you, it's fine, of course.

You might try changing it to window 1 instead of window "weird convoluted file name".

Example:

set value of text field 3 of sheet 1 of window 1  to "<string>"

As to the initial questions about how I setup AppleScripts, the posts @Tom provided in his reply are great references. I use UI Browser a lot. It has been discontinued, unfortunately, and there is no longer a way for new users to get a license, but those who already had one can continue to use it.

1 Like