ok,
we are on the probe/touch probe road.
in this case a macro, or a brain is to slow to do this.
G31 is your friend, try to read/learn a bit more about G31 (i realy do not want to patronize you),
but i think that is the functionalty you are looking for.
Tom