Z offset Macro

I'm working on a Z offset macro to help find the correct z offset value for the I.R. Probe.
I'm calling M291 to adjust Z so that it just touches the bed. But i can not seem to get the M291 paramaters correct.
I want the dialog to appear, wait for the user to cancel or OK and proceed running the remaining g code.

The dialog appears, and I can set S and T values so that the message displays until the user clicks OK but while the message is displayed the remaining G code runs?