Ah, that's definitely an interesting macro! From what I can see, it's as you described. If you're targeting the same thing as your pet, it will make your pet come back to you. If your pet has no target, your pet will attack, or if you target something else besides your pet's target, your pet will switch to that target. Very cool! Thank you for that contribution.
The macro I use simply sends your pet at the target, popping speed enhancers, like Charge or Dash, in the process. I use a different macro to bring my pet back to me, also popping speed enhancers, like Dash or Dive. I have a third macro for telling my pet to stay.