Yep, easy enough. Just use the IF/THEN like Chris @ccstone suggested.
You said "Toggle", so that is exactly what this Macro does.
It is just an example using BBEdit -- you need to adapt to your specific needs.
Put all you your apps to be toggled in BOTH sections of the IF/THEN.
But the Macro Group this is in should probably be a Global group, with no specific apps named.
MACRO: Toggle Activate/Hide Apps [Example]
~~~ VER: 1.0 2019-05-13 ~~~
Toggle Activate-Hide Apps [Example].kmmacros (3.8 KB)
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.