Hi Pablo,
It depends on the controller you're using, but one common approach is to use M-codes linked to an output signal. Some controllers allow you to assign an output to activate when a specific axis is moving.
If your system supports conditional logic or macros, you might be able to set up a function that enables the output when an X-axis move is commanded and disables it otherwise.
What machine/controller are you working with? That might help narrow down a solution.
Best regards,