Wholly a guess, since I haven’t looked at your code, but this is one of my favorite boo-boos:
I create an image just to hold plotting parameters, say one like 1,2,1,<n> for n xy plots, so that the image grows along the spectral (channel) axis as I add plots:
…
-input (50;32^234;213^ … x<sub>k</sub>;y<sub>k</sub> … ^ … x<sub>n–1</sub>_;y<sub>n–1</sub>)
-name. xyplots
-foreach { _<do stuff with every image on the list, each one in turn>_ }
…
If I do not provide a selection decorator on the foreach command, it will happily process every image on the list, including my data container image, xyplots. That does not, in itself, raise an error in a command line environment — G’MIC can deal with any number of channels — but when the script operates in the context of some host paint program, like Gimp, then that host will probably reactly badly to an image with anything more than four channels (RGBA, CMYK,…).
But, in general, foreach is like any other G’MIC command; it can take a selection decorator, so that:
-foreach[^xyplots] { _<do stuff with every image on the list, each one in turn, except xyplots>_ }
Ah. Have to look at what you’ve built tonight, sometime during the evening hours on the western side of the Atlantic seaboard…