I had wondered how to make a more functional Pendant controller than the ones that you can buy off the shelf. By more functional, I mean including DROs that are updated from Mach4 and confirmation lights on buttons, again controlled by Mach4 - so you know it has received and understood the instruction.

In place of Buttons, I've used a Capacitive Touch LCD (which works with wet fingers, unlike Resistive screens).

It uses an Arduino Nano as a USB Serial Device. When a button is pressed, it sends a (short) Serial Message to Mach4. When Mach4 receives it, it enacts it and sends back the state of the thing it changed (Coolant for example) which in turn causes the button to Illuminate.
The MPG Wheel Sends "I" for Increment & "D" for Decrement. If the DRO value for an axis changes, it's sent back to the Pendant for display. With the short messages and fast serial (115200bps) the lag is minimal making the pendant very responsive.
While this is not just a 'script', the scripts it contains may well be useful, particularly for anybody wanting to communicate externally using Serial. Most of the heavy lifting with the serial was done by Mike
https://www.machsupport.com/forum/index.php?topic=42084.msg274487#msg274487I used a variant of his code to talk to my Servo Drive - then adapted it for this.
DanTheGaz's posts & particularly videos were invaluable discovering what's under the covers of Mach4
I'm sure I've done some of it the 'wrong' way - but life is for learning!
I've uploaded all the code, including Arduino to GitHub:
https://github.com/SimonRafferty/Mach4-Serial-Pendant