Having a macro respond to a cooldown has been specifically disabled by Blizzard. In the past, this was accomplished by having one spell listed after the other like in the example below.
Code:
/cast Holy Fire
/cast Smite
However, Blizzard added in a check with every spellcast command to see if the GCD would've been triggered if a spell had been cast regardless of its personal cooldown or any other condition.
Prior to the SecureActionButton system, addons had direct access to functions like
CastSpell(). Because of addons that allowed the user to repeatedly mash one button to play. Blizzard implemented their taint system and locked the function so that only their code can use it.
To sum it up, no, you can't have a macro and/or an addon react and change spells (including actionbar pages) based on the conditions of a cooldown.