Skip to main content

Basic Automation Tasks

Small scripts that do real work

In This Lesson

What to Automate First

The best first automations are chores you already do constantly: resizing to a standard size, exporting to a web format, adding a copyright line, applying the same sharpening. Each is a short, fixed recipe — exactly what a script excels at. Master a couple of these and tomorrow's batch processing lets you run them across hundreds of files.

No Macro Recorder — Write It

Unlike some editors, GIMP has no "record my actions" macro feature. Instead you write the steps as a short script. That sounds harder, but it's more powerful: a written script is exact, editable, and reusable, and you build it straight from the procedure names you found in the Procedure Browser. Start in the Script-Fu Console, get each step working, then combine them.

💡 Build Step by Step

Test one command at a time in the console — scale, then flatten, then export — confirming each works on a copy. Only when every line behaves do you stitch them into one script. Debugging a 10-line script one line at a time is far easier than all at once.

A Resize-and-Export Script

A common recipe: scale the active image to 1200 px wide, flatten, and export a JPEG. In Script-Fu it looks like this (conceptually):

(let* ((image (car (gimp-image-list)))
       (w 1200)
       (h (/ (* w (car (gimp-image-height image)))
             (car (gimp-image-width image)))))
  (gimp-image-scale image w h)
  (gimp-image-flatten image)
  (file-jpeg-save RUN-NONINTERACTIVE
      image (car (gimp-image-get-active-drawable image))
      "/path/output.jpg" "output" 0.9 0 1 1 "" 0 1 0 0))

Each line is a PDB procedure you can look up. The height is computed from the width to keep the aspect ratio, and file-jpeg-save writes the result at 90% quality. Adjust the width, path, and quality to taste.

Looping Over Layers

Automation gets powerful with loops — do the same thing to every layer, or (tomorrow) every file. To apply an operation to each layer, get the layer list and iterate:

(let* ((image (car (gimp-image-list)))
       (layers (gimp-image-get-layers image))
       (num (car layers))
       (arr (cadr layers)))
  (let loop ((i 0))
    (when (< i num)
      (gimp-image-set-active-layer image (vector-ref arr i))
      ;; ... do something to this layer ...
      (loop (+ i 1)))))
flowchart LR A[Get list of layers] --> B[For each layer] B --> C[Apply the operation] C --> B B --> D[Done: flush display]

A loop applies one operation across many layers — the seed of batch processing.

Turning It Into a Menu Command

Once a script works in the console, wrap it in a function and register it so it becomes a real menu item you can click. A Script-Fu script ends with a (script-fu-register ...) call that names the function, its menu location (e.g. under Filters), and any parameters, plus a (script-fu-menu-register ...) for the menu path. Save the file to your personal scripts folder, Refresh Scripts, and your automation is now a permanent command — with an options dialog if you gave it parameters.

🎓 Parameters Make It Reusable

Register your resize script with a width parameter and GIMP builds a dialog for it automatically. Suddenly your one-off becomes a flexible tool anyone can use — the difference between a throwaway command and a lasting utility.

Practice Activities

  1. Console resize. Scale a copy of an image to a set width from the console, computing the height to keep the ratio.
  2. Export by script. Add a file-jpeg-save line and export the resized image to disk.
  3. Register it. Wrap your resize-and-export into a registered Script-Fu command with a width parameter and run it from the menu.

Summary

✅ Key Takeaways

  • Automate the chores you repeat: resize, export, copyright, sharpen.
  • GIMP has no macro recorder — you write short scripts from procedure names.
  • Build and test one command at a time in the console before combining.
  • Loops apply an operation across many layers (and, next, many files).
  • Register a working script — with parameters — to make it a permanent, reusable menu command.

➡️ What's Next

Thursday scales this to whole folders with Batch Processing Fundamentals.

Additional Resources