Just change 'mouseover' with 'target' on what he posted, like so:
Code:
/cast [nomod, @mouseover, help, exists] [nomod, @target, help, exists][@player] Power Word: Shield
That third condition wasn't necessary Taryble, the last one alone also covers the possibility that the person is holding a modifier.
But anyway, that macro won't try to cast on the target's target.
Code:
#showtooltip
/cast [nomod, @mouseover, help, exists][nomod, @target, help, exists][nomod, @targettarget, help, exists][@player]Power Word: Shield
I didn't test this second macro, but it should do the same as the above except that before casting the shield on yourself it should try to cast on your target's target if it's friendly.