I don’t know if you have written any macros before or not. I recently made my first.
The basic structure is declare the variables needed for the macro. save the initial state, do what you want to do, and then restore the initial state.
I found this section User Guide · cncjs/cncjs Wiki · GitHub to be very informative. gSender being a descendent of cncjs all info there is relevant.
If you need a gcode reference try LinuxCNC "G-code" Quick Reference you can get a feel what different gcodes do at the start and and click to get the full rundown on the ones you’re interested in.