The macro would be
/targetenemy
/petattack
/petfollow
The only problem is that /targetenemy doesn't target someone on the other side of the map. It has a range distance.
Edit: Apparently some of you are missing the point. Lets say you're in AB standing in the mountains somewhere alt tabbing. You have a good view of the entire battlefield. Someone says in BG chat to report you for afk. You alt tab back in and you see yourself with the inactive debuff. Instead of moving and attacking someone you just target someone, press your pet attack button, and then your pet follow button right after.