Apple script gets broken

I haev the apple script that makes the right click on selected event.

tell application "System Events"
	set frontApp to name of first process whose frontmost is true
	tell application process frontApp
		try
			set theSelection to value of attribute "AXFocusedUIElement"
			tell theSelection
				set defaultAction to perform action "AXShowMenu"
				if defaultAction is missing value then
					tell (first group whose selected is true) to perform action "AXShowMenu"
				end if
			end tell
		on error errMsg number errNum
			display alert errMsg & return & return & errNum
		end try
	end tell
end tell

And since yesterday it gets broken. It recalls the right click menu but than says

"System Events got an error: Can’t get group 1 of outline 1 of scroll area 1 of splitter group 1 of splitter group 1 of window "Send and track" of application process "Finder" whose selected = true. Invalid index.

-1719
"

Any idea why?

A complete guess -- have you, perhaps, changed from icon view to list or column view?

I have always used the list view. So nothing is changed. But now I've tried now the column view and it doesn't show the error. But i've never used it.

Something has changed -- UI elements don't change their position in the element hierarchy unless you change the view, have a different selection to what's expect, or similar.

But since this is very situational, only you will be able to work out what you've done so you can either not do it or add compensations into your script.

1 Like