Here is an example of one of my macro's for my Priest. Im sure there are other/better ways of doing it, but this works 100% fine for me atleast.
#showtooltip Power Word: Shield
/cast [mod,target=player][target=mouseover,help,nodead][help,nodead][nogroup,target=player][target=targettarget,help,nodead] Power Word: Shield
/tar (my name)
/cast Power word: Shield
/targetlasttarget
So if I dont have any friendly players (Enemy boss, for example) mouseovered, it casts it on me, if I have any friendly mouseovers at all, it casts it on them.
It acts like a mouseover macro atleast.