Target macro help please

Hi, I want a target enemy macro that uses smart targetting first and when I cast a spell either via mouseover or smarttargetting the macro selects that as my target and wont change targets unless I cast the macro again or the selected target is dead.
I tried
/targetenemy [harm] [dead]
/cast [mouseover] [exists] moonfire

doesnt work

It sounds like you want a focus macro.

/focus

And then your spells would be

#showtooltip /cast [@focus,exists,harm,nodead] Moonfire;Moonfire

This will always cast your spell at the focus target if it is a living enemy, otherwise it will just cast the spell normally.

There’s a line break after the #showtooltip, but this editor doesn’t like it for some reason.