I would like to know if there is a way to intercept the sending of g-code to the printer (after clicking Print), retrieving the active g-code command/s and run either bash commands from there? (without using any events, raw g-code interaction if possible).
Here's my sample thoughts on implementation of the modified g-code:
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mod
P01 ;code intercept (will not send to printer) run blink-gpio.py
S05 ;code intercept (will not send to printer) run sudo shutdown-pi.sh
Please note that those g-codes in example (P01, S05) will be added by a plug-in/s or other 3rd party tool/s.