(Classic 1.x) /stopattack not working when it's in the line above /startattack

I copied using /stopattack in my macros to stop wand-casts to cast regular spells from this Reddit-thread.

It would essentially work, but didn’t once I put this into my preexisting macro in which /startattack is in the line below /stopattack:

#showtooltip
/stopattack
/startattack
/petattack
/use Shadow Bolt

The above is a macro you’d use to automatically target a mob without having to tab or click it first and the issue I got after adding /startattack to it was I had to actually cancel the wanding-cast way before the wanding animation again, whereas with the same macro not containing stopattack it would be fine if I just stopped the wanding right before the next time it’d swing.

Another issue: Even without /startattack I’d have to hit the macro at least twice to make it work. I was hoping for a solution in which 1 hit would be enough.

Any workaround?

First off I’d try the following CVar

/console stopAutoAttackOnTargetChange 1

If that doesn’t eliminate the need for stopattack entirely, you could try the hunter thing and stack multiple of them. I also swapped startattack for targetenemy to see if that’ll help.

#showtooltip
/stopattack
/stopattack
/targetenemy [noharm]
/petattack
/cast Shadow Bolt

You could also try adding in /cqs to cancel the spell queue (if that version of the game uses it) before stopping the current attack.

#showtooltip
/cqs
/stopattack
/targetenemy [noharm]
/petattack
/cast Shadow Bolt

/cqs doesn’t work on my version of WoW.
/targetenemy [noharm] did the trick and I didn’t even need 2 stopattacks
I do however still have the problem that I need to hit the macro twice to be able to cast Shadow Bolt when I was just wanding.