Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Gimp 3.0.4 python batch interpreter oddities
#6
If you don't put quotes around the marker of the heredoc (EOF here) then bash substitution applies, so you can set variables in your code from bash variables:

Code:
#! /bin/bash

string="the quick brown fox jumps over the lazy dog"
step=4

read -r -d '' python << EOF
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp

string="$string"
step=$step

print(f"Running batch in Gimp {Gimp.version()}")  # Just shows that we imported Gimp correctly

for l in range(0,len(string)+step,step): # len(string)+step insures that we print the full string last
    print(f"{string[:l]}")
EOF

gimp -idf --batch-interpreter=python-fu-eval -b "$python" --quit

Also, since Gimp makes a special case of a single dash - used as an argument to -b to mean "read code  from stdin", you can feed the heredoc directly to Gimp (but the form with a variables could be easier to debug because you can check the result of substitutions before you pass it to Gimp:

Code:
#! /bin/bash

string="the quick brown fox jumps over the lazy dog"
step=4

gimp -idf --batch-interpreter=python-fu-eval -b - --quit << EOF
gi.require_version('Gimp', '3.0')
from gi.repository import Gimp

string="$string"
step=$step

print(f"Running batch in Gimp {Gimp.version()}")  # Just shows that we imported Gimp correctly

for l in range(0,len(string)+step,step): # len(string)+step insures that we print the full string last
    print(f"{string[:l]}")
EOF
Reply


Messages In This Thread
RE: Gimp 3.0.4 python batch interpreter oddities - by Ofnuts - 08-11-2025, 07:30 AM

Forum Jump: