If I have a focus, and it has a target then .. Cast Hunter's Mark, petattack, startattack
If no focus target, but my pet has a target .. Cast Hunter's Mark, petattack, startattack
If no focus or no pet target then it targets the nearest attackable enemy and then stops. The NEXT click, because you now have a target, will target the sequence and send in your pet.

I have a question on this bit - Why does it target ANYTHING at all with no pettarget or no focustarget? I think it is the /petattack [target=target, exists] - its like WoW can't help itself, it MUST target something, although it doesn't send the pet in.

If I hold down any modifier key - control or alt or shift then it will still follow the same logic, the pet will attack, BUT, no Hunter's Mark and no startattack

If I understand correctly you want your macro to select a target and the use three additional command on the target selected. Therefore, the final three are easiest.

What the main issue seems to be is selecting your target, here is what I came up with:

Code:

if the pet has a target
select the pet's target as my target
if (my focus has a target and the mod key is pressed)
select my focus' target as my target
if I do not have a target
select the nearest enemy as my target
if i do not have a target
stop the macro
/cast (...)