AppleScript & KM Variable String vs Number

Hi all,

This AppleScript works just fine:

set TrackUIElement to 9

tell application "System Events"
tell process "Logic Pro X"
click button 1 of UI element TrackUIElement of ( groups whose value of attribute "AXDescription" is "Tracks header") of scroll area 1 of splitter group 2 of splitter group 1 of group 2 of ( groups whose value of attribute "AXDescription" contains "Tracks") of group 2 of ( first window whose value of attribute "AXTitle" contains " - Tracks")
end tell
end tell

But when I try to do this using a KM Variable (that is set to 9 in this case) it does NOT work:

tell application "Keyboard Maestro Engine"
set TrackUIElement to getvariable "FZ__TrackUIElement"
end tell

tell application "System Events"
tell process "Logic Pro X"
click button 1 of UI element TrackUIElement of ( groups whose value of attribute "AXDescription" is "Tracks header") of scroll area 1 of splitter group 2 of splitter group 1 of group 2 of ( groups whose value of attribute "AXDescription" contains "Tracks") of group 2 of ( first window whose value of attribute "AXTitle" contains " - Tracks")
end tell
end tell

The error returned is this:

System Events got an error: Can’t get UI element "9" of every group of ...

It's strange because when I add a display dialog to the KM script:

display dialog TrackUIElement

It indeed shows me just "9" without the quotes.

I'm using the TrackUIElement variable to replace the 9 in "UI element 9".

Any idea what's going on?

Thanks!

FYI this was a simple fix.

The KM variable was a "string" to AppleScript so this worked:

tell application "Keyboard Maestro Engine"
set TrackUIElement to ( getvariable "FZ__TrackUIElement") as number
end tell