This requires SuperMacro, but it works great:
/script PetDefensiveMode()PetAttack();if CheckInteractDistance("target",3)and(not PlayerFrame.inCombat)then AttackTarget()elseif not IsAutoRepeatAction(1)then cast("Auto Shot") end if not buffed("Hunter's Mark",'target') then cast("Hunter's Mark") end
Put Auto Shot on button 1 - or change IsAutoRepeatAction(1) to the button you want it on.