@konk you can use triggers on a GPIO pin to run a macro. Think its M581 to define the pin as a trigger. This page details how to do it:
https://duet3d.dozuki.com/Wiki/Using_M581_-_External_Triggers_and_Building_a_Control_Panel