WoW's macro system works like this, and you can set conditionals to it.

/cast [@mouseover][help, nodead] [] spell name

Will cast on mouse over, friendly target that is alive, and yourself if those conditions are not met.

I also had macros that would cast heals if my mouse over or hard target was friendly, but attacks and offensive spells if hostile on my Mistweavers monk.

Macros like that would save a *lot* of space on hoybars for my Scholar...