Simple answer - You Can’t.
Longer answer - mods and macros are prevented from being able to ACT on this information. Mods can either SEE or they can ACT they can’t do both. You have to work around this to achieve what you are after - and by that I mean deliberately know that clicking this ability to move it to the next - that line will fail as it’s on cooldown but the next one will work. To do this a number of people wrote their macro to take this into account and “spam” their macro so that it will work for them.
In the same way a mod or macro cannot tell if a proc has happened or that it is the right time to cast a particular spell. It has not ability to perform an if/then consideration beyond simple things like “if alt is held down then” or “if I have this talent then” or “if I’m
In combat then”.
It can’t do if the mob has less than 20% health then … now for pallies and warriors and hunters their execute like ability won’t work so you throw it in knowing it will become active when it can. This technique doesn’t work for Shadow Priests where using SW:D has other consequences.