Custom-defined routines with Gcode commands

Hi Guys,
I’ve got a question about the Gcode functionalities with URCap. I know I can use a .nc file to define a toolpath and configure the ports of the UR to abilitate the end-effector tool (basically what is explained in Tabletop Demo of Regular TCP Toolpath Moves and other similar tutorials).
I would like to know if it is possible to associate a custom defined ur script to a certain Gcode command, for example when in the .nc file there is the M12 command the robot executes a subroutine defined elsewhere. Basically i want to be able to define other operations (ur functions) to be done during the Gcode toolpath execution, without the need to split the Gcode in different files.

Thank you in advance for your help and advice.