Have you tried with the M7 on the same line as your next G1 move?
If that doesnt work then the only way I can think of is tricking Mach to think you have another axis and using the Dir signal of that axis for switching the relay. That will require you to have the false axis move one direction to switch on and another to switch off, how well it will work I am unsure.
Hood