How to Select a Virtual Instrument in Logic Pro X. Is It Possible?

Hey guys. Just wanted to share my method. My KM macro pastes the name of the desired Logic plugin into PlugSearch, after figuring out the best place to insert the plugin, using multiple found images and nested if/else actions. When a button is pressed, it will either:

a) insert a new instrument plugin if the visible track header contains an empty instrument slot or...
b) insert an audio plugin in the first available track header slot.

I'm using a Stream Deck and the excellent "KMLink" plugin to assign a different Logic plugin name to each button. All you have to do to set up a button is enter the name of the Logic plugin name into that button's KMLink parameter box (in lower case), which is then passed on to KM to paste into PlugSearch.

Here's a demo of it in action.