Switch between "actually active" apps based on a list?

Hi, I'm trying to figure out how to do this:

I'd prefer to use a footpedal, hooked to a Korg padKontrol, in such a way, that if I press the footpedal down, it will switch between the currently active apps from a list.

So, the list would be something like this:
Pure Data
Apple Logic Pro X
Ableton Live
Renoise

And if some of them are not active (=not open), then they get skipped, and the stepping on a pedal will switch between the ones that actually are active.

This would really greatly help me in my works, and I'd love to find out how to do it.

I already have a mouse button activating a specific app and bringing it up front, and another mouse button activating another app, and that's fine, but switching between "what's there" instead of "load it up and switch to it" is what I'm after now.

This would be based on a midi trigger, as far as I can understand. Is this possible? So like a "carousel switcher"?

See this thread and I suggest you contact How to use a MIDI Controller slider to control system volume?

and I suggest you message

zzz2496

Damir Handoyo

to see what he is doing since 2017.

hmm. well, if i was not mentioning the midicontroller aspect of this, how much work would it require for me to have a list that goes "ok, one app out of 4 apps is now active, so switch to the second one, then third one, then fourth one"..?

Seems like it'd be pretty easy to do with a series of if/thens. There may be a more elegant way to do it, but this should work?