This is really a question about AppleScript (albeit triggered by KM) so I hope that's OK!
I have AppleScripts set up so I can change parameters in Logic Pro on my Stream Deck via Keyboard Maestro, but at some point recently (presumably a Logic update, but could be Monterey), they stopped working. Of course they are all GUI Scripting so vulnerable to breaking if the UI changes, but it doesn't look like anything has changed.
Here is a short, heavily simplified version of a sample script to set fade type to EqP:
tell application "Logic Pro X"
activate
end tell
tell application "System Events"
tell process "Logic Pro X"
set _TracksWindow to title of first window whose title contains "- Tracks"
tell pop up button 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window _TracksWindow
click
delay 0.2
click menu item "EqP (Equal Power Crossfade)" of menu 1
end tell
end tell
end tell
This used to work, but now it throws up an error saying it doesn't know what "menu 1" is.
All the 'directions' up to that point seem to be fine (the error only comes at the "click menu item" line) so I don't think any of the row/area/group/etc numbers are wrong. Interestingly it does seem to 'click' the pop-up before it throws the error (see screenshot - it halts with EqP still highlighted).
I'm pretty stumped, as it seems to locate the pop-up fine, but then fails when I try to actually select something from it. Can anyone see why it doesn't work?
set tracks_window to title of first window whose title contains "- Tracks"
click pop up button 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
--delay 0.05 --pause doesn't seem necessary any more
click menu item "EqP (Equal Power Crossfade)" of menu 1 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window tracks_window
Incidentally, I wasn't able to get this working with local variables for some reason. Perhaps it has something to do with as number butting up against instance inst. I wrote this so long ago that I can't even remember why as number was necessary. I tried:
set inst to system attribute "KMINSTANCE"
tell application "Keyboard Maestro Engine"
set FadeLengthAS to (getvariable "Local__FadeLength") as number instance inst
end tell
It didn't work, so the macros above still use global variables. If anyone reading this can shed light on the local/global thing, please do! (@Nige_S?)
return UI elements of pop up button 1 of row 14 of outline 1 of scroll area 1 of group 1 of list 1 of group 2 of window _TracksWindow
It comes out blank. Like it doesn't think the pop up button contains anything?
Apologies if this is nonsense, I learned just enough AppleScript to make this work a couple of years ago and now I can't really remember how it all works!
Using UI Browser to check, it looks like the "address" of the button is all correct up to the pop up button. But it doesn't seem to see "menu 1" when it gets there.
I'd guess your order of precedence is wrong -- try
set FadeLengthAS to (getvariable "Local__FadeLength" instance inst) as number
(AS sees all KM variables as text unless you tell it otherwise, other explicitly as above or implicitly by using it as a number in a calculation etc. So get the value then cast it to a number, doing it immediately as above in case you forget later!)