My penance set-up is something I’ve been using for a few years now and I’ve never had the need to alter it so I guess I’m pretty happy with it, might not be exactly what you ask for but maybe you can take the idea and adjust it to your liking.
Basically what I do is that no-modifier will be my Offensive penance macro which will under no circumstance cast a defensive penance, so it’s always offensive penance with priority: Mouseover > Target > (do nothing). Then when I use “shift” as modifier it will always be a defensive penance and like the other case, it will under no circumstance cast offensive penance, my priory for this one is: Mouseover > Target > Self.
Because of my specific set-up I actually have it split into two different macros but you can probably combine them into one by using “shift” as conditional.
Offensive Penance:
#showtooltip Penance
/cast [@mouseover, harm, nodead] Penance [@target, harm, nodead] Penance
Defensive Penance:
#showtooltip Penance
/cast [@mouseover, help, nodead] Penance [@target, help, nodead] Penance [@player] Penance