At the top of my head, the only thing I can think of is using
https://warcraft.wiki.gg/wiki/COMBAT_LOG_EVENT
Create a table of spellIDs to monitor, with spellIDs to cast yourself following their casts
You *might* be able to use the secure environment to set the spell ID of a secure button while in combat, that you then click.
A similar addon is
https://www.wowinterface.com/downloa...ityHelper.html which updates based on current combat situation. You might be able to use something they have to aid you in your idea.
Hopefully this will help in some way or that someone has a better suggestion for you. In either case, good luck.