The macro system is intentionally not as programmatic as WoW. You can automate a few actions, but it will never "play the game for you." The devs posted their internal design principles for macro creation at some point and a lot of them seemed to be centered around avoiding commands that included some logic or automated decision-making on the client.

The only real options you have at the moment are to write something that is always executed from top to bottom, with a wait command to handle the GCD if necessary.