How can I batch process JPG images to change their quality with Nautilus-Actions?

Solution 1:

You cannot use %F twice in a command like that, because %F gets replaced by the names of every file selected. For example, a command of sh with parameters -c 'printf "%%s\n" "$@" > foo' %F %F will create a file named foo with the names of every file selected, twice. Therefore the convert command that actually runs is:

convert file1.jpg file2.jpg ... -quality 80% file1.jpg file2.jpg ... fileN.jpg-80q.jpg

And since the last file is taken to be the output file name, only it will matter.

What you can do is wrap your command in bash -c and run a for loop:

bash -c 'for i; do convert "$i" -quality 80% "${i/%.jpg/-80q.jpg}"; done'

(where I am assuming that all files end with .jpg)

In an action, you will have bash as the command, and for the parameters:

-c 'for i; do convert "$i" -quality 80%% "${i/%%.jpg/-80q.jpg}"; done' - %F

You can make this more complicated to handle any extension, at which point you might as well skip Actions and use scripting.