I found these variations of Righteous Defense macros.
#showtooltip Righteous Defense
/cast [help] [target=targettarget, help] Righteous Defense
This will first check if you target is friendly and if so cast on them. If not, it will check that your target's target is friendly and cast on it instead.
- - -
#showtooltip Righteous Defense
/cast [target=focus,exists,help][help][target=targettarget,help] Righteous Defense
This will cast RD on your focused mob's target. If there's no focus, it does nothing.
- - -
#showtooltip Righteous Defense
/cast [modifier:alt,target=none][help][target=targettarget,help] Righteous Defense
If you hold down the alt key when activating the macro, your current target is ignored completely and instead you can choose any friendly toon or target frame.