Changing Parameter in Logic Pro With AppleScript

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.

Screenshot 2022-12-02 at 10.24.43

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).

Screenshot 2022-12-02 at 10.24.36

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?

Thanks!

Funnily enough I noticed this yesterday and had to adjust my own fade macros, which pass fade values from KM Link's parameter box on the Stream Deck:

Fade Macros.kmmacros (184.0 KB)

The bit you're specifically asking about is:

				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?)

I don't know if this is relevant but if I add:

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!)

1 Like

Thanks so much @noisneil that seems to have fixed it!

Are you able to tell me why this works...

click pop up button 1 [etc.]

but this (since recently) returns an error (but not until the following line)?

tell pop up button 1 [etc.]
click

YUP! Here are the macros again with local variables:

Fade Macros.kmmacros (184.0 KB)

I'm so rubbish at AppleScript, so @Nige_S is a better bet.

Haha me too! Thanks for the help. I’ve put the whole thing into your macros mega thread, as it’s a slightly different take on the UX.

1 Like

Have you tried click me rather than just click?

Though I'm not sure why you'd use that construct over click pop up button.... Three lines rather than one? Think of the planet!

I didn't know the shorter way was possible when I first made the script!

Now I'm just curious to know why the longer way, which did work, has broken.