How do I get Automator to process images using ImageMagick in a command script?

I'm making an Automator workflow that uses the shell script action to process a selection of images with the imagemagick composite command. Only I'm having issues getting it going. According to the results I get when I run the workflow, everything is working however, I know it's not due to the fact that the changes I'd expect to see in the folder of images are not present. I know that the imagemagick command I'm using is correct as it works correctly from the console. (I echoed the composite command to the output & copied it into a Terminal session. Ran like a charm). BTW: The workflow's for processing a fade in on a stop motion movie I made. Yes I know I could use video tools to achieve the same thing, but the ones I have access to screw up the image quality on output.

Here's the script

imagesCount=$#
rate=$(echo "scale=2; 100/$imagesCount"|bc)
percentage=$rate
for f in "$@"; do
    fileName=${f%.*}
    composite -blend "$percentage" -size 1280x720 "$f" xc:black -alpha Set "$fileName-1.jpg"
    percentage=$(echo "scale=2; $percentage+$rate"|bc)
done

At first I thought at the cause of the problem might be spaces in the paths, but I removed this possibility by shifting the files to a path without spaces, but that had no effect.

I'm almost certain the issue is related to something in the bash command but I don't know bash at all, this is my first time writing any bash command scripts, but I am very knowledgeable in Windows console scripting and would have no trouble getting this to work there.

If the error in the script isn't obvious enough to catch, would someone propose a method to debug this so I can figure out why the images are not getting processed even though the script runs without error?


Solution 1:

I would just do the whole thing at the command line as a shell script instead of using Automator to launch it. Put #!/bin/bash as the first line, and run it as

myscript.sh image*.png

where image*.png is your set of image files that you are apparently selecting in Automator?

If you need to run it on all files in a folder, that can be done too.

You can also test your script in automator using echo ${f%.*} instead of the commands themselves.

Solution 2:

Replace for $f with for f. for $f in aa; do :; done results in an error like `$f': not a valid identifier.

Also if composite is not on the path, specify the full path to it (like /usr/local/bin/composite).