Execute custom gcode scripts

We are looking for a way to execute custom gcode scripts.

We made a custom gcode script and put it in the gcode folder next to beforePrintResumed and so on.
We can execute the script from a button in the custom control editor.

Is it possible to execute the script in any other way like the action command plugin, or a gcode command?

Who's this "we"? Do you have a mouse in your pocket?

Move your script to ~/scripts. Adjust the path in your Gcode System Command to /home/pi/scripts/myscript, for example. Adjust the rights of the file with something like sudo chmod a+x ~/scripts/myscript to make sure it can run. Make sure that paths inside the script have full paths instead of assuming that anything is in the path or that you're in a certain directory.

You'll end up with something like OCTO900 which runs your script. You want to make sure that nothing in the script is blocking. If so, append an ampersand at the end of that line so that it runs in the background.

I do something similar and then I add OCTO805, for example, in my Gcode scripts to alert me that the print job is done (playing a sound event which is R2D2's whistle).

I am trying to execute a gcode script not a shell script.
So there is only gcodes in the script.

script is :

{% if last_temperature[last_position.t]['target'] <= 201 %}
M301 P12 I0.6 D66
{% elif last_temperature[last_position.t]['target'] <= 251 %}
M301 P14 I0.6 D66
{% elif last_temperature[last_position.t]['target'] <= 301 %}
M301 P16 I0.6 D66
{% elif last_temperature[last_position.t]['target'] <= 351 %}
M301 P18 I0.6 D66
{% else %}
M301 P20 I0.6 D66
{% endif %}

M117 PID changed

and needs to be executed after each M104 and M109 that comes through

I guess the better way of asking the question would be, "how do I hook into the gcode stream and do something (call a script) specifically when certain gcode commands are seen?"

Take a look at this single-file plugin which foosel created. It hooks into the gcode stream and does something specific when it detects a particular style of temperature-related response from the printer. You might modify this approach for your own needs. She is describing what to do with it here.

There's also a recent plugin that was added that will allow for replacing stuff in the gcode stream, but I don't think it supports scripting/parameter replacement.

@kantlivelong might know more about this since he recently has worked with the gcode scripting stuff.

Hooking into the gcode stream is done with the terminal response plugin. And as jneilliii stated, that will let me sent individual lines of gcode or execute a shell script.
Where I would like to execute a gcode script or a gcode snippet.
I was thinking that if a gcode line came through the stream that looked like


then the line would not be sent to the printer, but the set_pid snippet would be executed