Macros can't do unit comparisons. The best you can do is select based what modifier key you're holding and fallbacks.
For example, this casts Power Infusion if you have a valid mouseover unit and you're not holding a modifier key, otherwise it casts Power Word: Shield on yourself.
Code:
/cast [@mouseover,nomod,help,nodead] Power Infusion; [@player] Power Word: Shield