How do I capture

Using Accessibility Inspector I exposed the hierarchy of this element (right click menu) which is Application-StandardWindow-Menu-MenuItem. The menu pop up appears on clicking however I can’t target it with script because the script doesn’t see the reference menu 1 of window “iTunes” (enclosed with “System Events” and application process blocks, of course). My script depends on existence of this menu.

NB. A link to my image failed to embed the image.

Model: MacBook Pro
AppleScript: 2.2.1
Browser: Safari 534.57.7
Operating System: macOS 10.7

May you tell us which window is supposed to be hosting the UI elements to trigger?

I am unable to guess which one it is.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 26 janvier 2020 21:42:01

The hosting window is window “iTunes”. The pop-up menu (aka context dialog) opens when
(1) the row is selected (“AXOutlineRow”). The row is a track with all its properties (number, plays count, date added, equalizer etc) in the list view.
(2) action “AXShowMenu” performed on it
(3) the pop-up (menu) appears
(4) a menu item named TheName should be activated by performing the action “AXPress”.

The problem is with the point 3. The script doesn’t see the element reported by the Inspector as a child of the window “iTunes” (and it’s this window, not any other one).

Model: MacBook Pro
AppleScript: 2.2.1
Browser: Safari 534.57.7
Operating System: macOS 10.7

I got it :

tell application "iTunes" to activate
tell application "System Events" to tell process "iTunes"
	set frontmost to true
	tell window 1
		-- class of UI elements --> {button, button, pop up button, radio group, radio group, button, button, button, slider, scroll area, pop up button, text field, button, button, button, splitter group}
		tell splitter group 1
			-- class of UI elements--> {browser, splitter, scroll area}
			tell scroll area 1
				-- class of UI elements--> {outline, scroll bar, scroll bar}
				tell outline 1
					-- class of UI elements --> {group, column, column, column, column, column, column, column, column, column, column, column, column, column, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row, row,…}
					tell row 8
						set its selected to true
						perform action "AXShowMenu"
					end tell
				end tell
			end tell
		end tell
		
		repeat 100 times
			set uiElements to class of UI elements --> {button, button, pop up button, radio group, radio group, button, button, button, slider, scroll area, pop up button, text field, button, button, button, splitter group, menu}
			if uiElements contains menu then exit repeat
			delay 1
		end repeat
		
		tell UI element -1 -- replace tell menu 1
			click it
			-- name of menu items of menu 1 -- is the standard syntax but here it fails.
			name of menu items --> {"Supprimer le téléchargement", "Ajouter à la playlist", missing value, "Lire ensuite", "Lire plus tard", "Créer une station", "Suggestions Genius", missing value, "Informations sur le morceau", "Aimer", "Je n’aime pas", "Décocher la sélection", missing value, "Afficher l’album dans la bibliothèque", "Afficher dans Apple Music", "Afficher dans l’iTunes Store", "Partager le morceau", missing value, "Copier", missing value, "Supprimer de la bibliothèque"}
		end tell
		
	end tell
end tell

The wanted item appears in the list of UI elements as a menu item but it’s not really a standard one.
If we try to trigger it as a menu we get an error.
We must trigger it as 'ui element ‘1’ which means the last of the list.
And we discover that it’s not built like a standard menu, the menu items aren’t belonging to menu 1 of the menu but they belong to the menu itself.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) dimanche 26 janvier 2020 22:57:27