What is the trick to using gcode_buttons in a macro?

Hi
Seems you are trying to solve similar task which was already solved.
Take a look here: Secondary needle calibration
Maybe you can adapt it to your needs.