简体   繁体   English

使用Guetzli监视文件夹并压缩jpeg的自动脚本

[英]Automator Script to watch folder and compress jpegs with Guetzli

I am trying to create a folder action to compress images with guetzli . 我正在尝试创建一个文件夹动作来使用guetzli压缩图像。 I am watching the images folder and if there is an image without 'compp' in filename I run guetzli on it. 我正在查看图像文件夹,并且如果文件名中包含不带“ compp”的图像,则在其上运行guetzli。 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, ie `test-compp.jp, test-compp-compp.jpg'. 如果我从automator中运行它,效果很好,但是当我保存它时,它会陷入无限循环,并创建同一文件的多个版本,并向其中添加compp ,即`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

在此处输入图片说明

You're missing the condition to check that the filename doesn't already have the string compp in it. 您缺少检查文件名中是否没有字符串compp的条件。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM