Send g-code when other g-code executes?

My CR-10 had the motherboard fan wired permanently on which made my work area noisy for no reason. I just replaced the motherboard and I connected it's fan to FAN_0. So I can turn the fan on and off easily with g-code (M106,M107). I plan on putting the fan-on command in the prefix g-code and fan-off in post g-code so that it only runs when printing. I will also be able to turn it on and off from the control tab.

It also would be nice if it always turned on when any motor command is given for any reason. This would avoid my overheating driver chips when forgetting to turn it on.

To make a very long story shorter, is there a plugin that would allow me to watch for specific g-codes and then insert my custom g-code when those codes are sent?

After putting the unit back together I discovered it was the fan in the power supply that was loud, annoying, and on all the time. I'll look for a supply that only spins the fan when hot.

It still bothers me that the motherboard fan runs all the time.

Wow, ask and you shall receive. I ask for this feature 12 hours ago and a new plugin appears that does exactly what I want. Is this a coincidence? :slight_smile:

Edit: the plugin is Terminal Response.