I thought I would bump this old topic to point out some new functionality planned for the upcoming 1.5 patch that might negate the need for all the complicated coding in the macro.
From Slouken at the Blizzard Marcos and UI Forum:
Apparently "targettargettarget" also works :)
Chris
From Slouken at the Blizzard Marcos and UI Forum:
Quote: In the next big content patch (1.5.0), you'll be able to append "target", to existing unit names to get information about those targets, if they are in your area of interest. You won't get events about those targets, but you'll be able to query information about them.
For example, to target your target's target, similar to an assist, you might do:
TargetUnit("targettarget");
If you wanted to see whether your pet's target was fighting your pet, you might do:
UnitIsUnit("pet", "pettargettarget");
Apparently "targettargettarget" also works :)
Chris