Lazy Targeting/Assist Macro

I am trying to write a macro that will automatically target whatever my focus (the tank) has targeted. However, I also need it to allow me to switch targets to other mobs as necessary for misdirects or trash mobs the tank is not necessarily targeting. What I want is this: When I have no target it should automatically target the tanks target, but if I need to switch to something other than the tanks target, it should keep my new target until the mob is dead. I know many of you will say I should just tab target and forget about this type of macro. But sometimes in the heat of an encounter I have tabbed and pulled mobs unnecessarily.

This is what I have thus far:

#showtooltip
/cast [harm]Cobra Shot
/assist [@focus,exists][@pet,exists]
/cast Cobra Shot
/petassist
/script UIErrorsFrame:Clear()

This almost does what I want it to do. It does allow me to switch from the tanks target to whatever I choose to target myself, but only for one shot and then it goes straight back to the tanks target. I need it to stay on what I switch to until that mob is dead and then return to the “assist”. What do i need to add to the “/cast [harm]Cobra Shot” that will stay on my target until dead?

could try
/assist [@focus,exists,nodead,mod:alt][@pet,exists]
not quite what your looking for but will prevent you from targeting something after the tank kills his target.
that way you can hand pick a target then just alt back to assist.
or you can make a duplicate macro just for your hand picked target without the assist.

I believe I found the solution. I added a /stopmacro [@target, exits] right after the /cast [harm]Cobra Shot.
So now I have:

#showtooltip
/cast [harm]Cobra Shot
/stopmacro [@target, exists]
/assist [@focus,exists][@pet,exists]
/cast Cobra Shot
/petassist
/script UIErrorsFrame:Clear()

Now I can switch from my tanks target to any mob I like and continue dps’ing that mob until its dead, at which point the macro automatically targets my focus target. It seems to work, at least on the training dummies using my pet as my focus.