Macro Help on target

Hopefully, this is in the right spot.

I would like to create a Macro for my hunter, that if I click on one of my spells and there is no target it will target the target of my focus and cast the spell. If I do not have a target it will target the next near mod and cast the spell.

#showtooltip
Aimed Shot
/cleartarget [dead][noharm]
/stopmacro [exists]
/tar [@focustarget,exists,harm]
/targetenemy [@target,noexists]
/cast Aimed Shot

I tried the follow and the first spell cast works, but when I press the button a second time, or any other button nothing happens. My chat states that “you aren’t in an instance group” Any help on how to make this work or a better way to accomplish this would be really helpful.

Thanks in advance

I never got it to do a sequence pushing the same macro other than the first spell.This I would like to know as well.

Removed the first reference of the spell “Aimed Shot” it was causing me to spam raid/party chat and was not needed.

the “/stopmacro [exists}” was working correctly, I just understood it wrong. it the condition above was true it prevents the macro from continuing. the condition that I had a valid target so I would not let the macro get the cast part of the macro. Removed those two from the macro and it sort of work.

It is always select the focus target now even if I have a target selected. I would like it to only select the focus target if I did not have a target already selected. Right now the working macro looks like this

#showtooltip
/cleartarget [dead][noharm]
/tar [@focustarget,exists,harm]
/targetenemy [@target,noexists]
/cast Aimed Shot