AXMenuItem question, help required please

Hi Everyone,

There is a fly-out menu item I’m trying to trigger in Acrobat Pro. The menu in question is accessed via a right-click.
Using UIBrowser I can see the AXMenuItem in the UI Browser Screen Reader, however I can’t see this in the Browser.
Is there a away to trigger the menu item using AppleScript Objective-C, or just Applescript, or does the fly-out menu have to be showing?

Thanks :slight_smile:

A screenshot of the element you wish to access would assist in helping to figure out a possible course of action. Judging from the description, that menu item is enclosed in a parent UI object that can be accessed more easily.

Since the desired element is a menu item you need to raise the menu first. To achieve that, target you script at this menu and inspect it for the presense of the perform action type as typically menus and other UI objects have associated actions to perform on them. I use Accessibility Inspector as part of Xcode. In the Inspector’s layout the actions are tucked up in the “Actions” section. The action you want should be something like “Cancel”, “Press” or “Raise”: in the domain of AppleScript names of UI actions are prepended with “AX”.

If the actions exist then you can build code in line with the following pseudocode:

tell application "System Events"

tell application process "Acrobat Pro"

set frontmost to true

tell window 1

tell menu bar 1 to tell menu bar item 1

perform action "AXPress" -- or "AXRaise" if there's no "Press".

repeat until menu 1 exists

delay 0.1

end repeat

tell menu 1 to tell menu item "My_item" to perform action "AXPress" -- your element

end tell

end tell

end tell

end tell

Note Code blocks in the example may not be balanced. I scrawled it for the demo purpose.

Hi there,
Thanks for the help.

Here is a screen grab of the item I’m trying to click…
It’s not part of one of the normal menus, if it were I’d most likely be able to access it with Acrobat Javascript.

I’ll have a look at the Accessibility Inspector in Xcode, thanks for that :+1:

Adobe programs are hard if not impossible to GUI script in AppleScript. Since a lot of Adobe programs don’t use the OS built in graphics routines for thing such as windows, and popup menus and toolbars, it cant be referenced using the GUI statements.
They wrote their own so it would be cross platform, but it also makes it not optimized for either platforms that they’re on. That was why Steve Jobs hated Adobe so much.

I don’t have Acrobat Pro, but i do have Acrobat Reader.
Run my script below when you have the Reader application open

tell application "System Events"
	tell application process "AdobeReader"
		get UI elements of window 1
	end tell
end tell

You will notice it returns an empty list since it cant find any MacOS based Elements since Adobe doesn’t use them. The only thing it uses is the Menu Bar at the top

1 Like

Thanks for the help and the code.

I tried running it but didn’t get much apart from buttons linked to the window.
Though it didn’t return much your code did make me wonder if I was targeting the right process and turns out I don’t think I was.
Pity about the Adobe thing, I’d been trying to use Acorbat Javascript to get what I wanted but the fly-out menu item isn’t available. Think it would take a plug-in to do it.

Thanks again for your reply.

If none of the GUI scripting and conventional coding is of any help, then the only recourse to access this item would be Keyboard Maestro. It has a configurable screen scanning action (“Find image”) embedded in other actions. The discussed issue is a typical scenario that the action was designed in mind. The action can detect any graphics on the screen and simulate user interaction, such as clicks, drags, and taps with or without modifier keys.

1 Like

HI there,

Thanks for the reply and for the info re Keyboard Maestro.

I’d actually found that at the same time I was looking for a solution.
Having dug around further I think it’s going to be KM or a plugin.
I’ll have a look at the “Find Image” thing :+1:

Thanks again for the help.