Help creating a macro

Hello all,

I want to create a blessing of freedom macro that has a few conditions. Can someone help dissect if this is possible at all:

I would like the macro to use spell on party2 if party2 exists and is in range
if not, I would like it to use spell on party1 if party1 exists and is in range
if not, I would like it to use spell on target if target is friendly
and lastly, if no target or target is hostile cast it on myself as default

Thanks for the help

macros are unable to do range checks unfortunately for you

Isn’t unbound getting changed so it auto hits an ally if you target yourself with it?