0

I am trying to create a folder action to compress images with guetzli. I am watching the images folder and if there is an image without 'compp' in filename I run guetzli on it. Here is the script. It works great if I run it from automator but when I save it, it goes in an infinite loop and creates multiple version of the same file and adds compp to it, i.e `test-compp.jp, test-compp-compp.jpg'. Not sure what I am missing.

for img in "$@"
do
filename=${img%.*}-compp
    /usr/local/Cellar/guetzli/1.0.1/bin/guetzli --quality 85 "$img" "$filename.jpg"
    echo "$img"
done

enter image description here

Yasin Yaqoobi
  • 1,888
  • 3
  • 27
  • 38

1 Answers1

1

You're missing the condition to check that the filename doesn't already have the string compp in it. Therefore a new file is created each time, which'll invoke a new execution ad infinitum.

Adding the conditional should work, ie.

for img in "$@"; do
    [[ $img == *"compp"* ]] && continue
    filename=${img%.*}-compp
    /usr/local/Cellar/guetzli/1.0.1/bin/guetzli --quality 85 "$img" "$filename.jpg"
    echo "$img"
done
Olli K
  • 1,720
  • 1
  • 16
  • 17