-1

I'd like to use a user defined action in Xfce for converting pictures.

Therefore i wrote

for i in %F; do filename=$(basename "$i"); 
    extension="${filename##*.}";
    filename="${filename%.*}";
    convert -resize 1024 $i $filename-1024px.$extension;
done

But this one don't works...whereas when i execute it in a shell (* instead of %F) it's working.

for i in *; do filename=$(basename "$i"); 
    extension="${filename##*.}";
    filename="${filename%.*}";
    convert -resize 1024 $i $filename-1024px.$extension;
done

I think there is a problem with the storage of the variables?

Edit:

This still works:

for i in %F;
    do filename=$(basename "$i");
    extension="${filename##*.}";
    notify-send "$filename";
done

After change to the following code it stops working:

for i in %F;
    do filename=$(basename "$i");
    extension="${filename##*.}";
    filename="${filename%.*}";
    notify-send "$filename";
done
rwx
  • 11
  • 2
  • What is `%F` supposed to be? – Etan Reisner Apr 08 '15 at 21:40
  • @EtanReisner %F — The paths to all selected files. E.g. if i do `for i in %F; do notify-send "$i"; done` i get the full path displayed of all files that are selected. – rwx Apr 08 '15 at 21:45
  • That's an xfce action thing? What about that snippet isn't working then? Are you getting `%F` literally in the script? – Etan Reisner Apr 08 '15 at 21:48
  • Yes this is an Xfce [action](http://docs.xfce.org/xfce/thunar/custom-actions). I normally get `%F` and it's working with simple stuff like example above or `for i in %F; do convert -resize 1024 $i $i; done` – rwx Apr 08 '15 at 21:56
  • So what **exactly** about that above snippet isn't working? – Etan Reisner Apr 08 '15 at 22:00
  • @EtanReisner I edited to try to show when the error occurs. – rwx Apr 08 '15 at 22:18
  • What does "stops working" mean exactly? Does it error? Does it not run at all? Does it eat your cat? – Etan Reisner Apr 08 '15 at 22:24
  • Oh! I bet the xfce formatter is being stupid and expanding `%.` or erroring on it. You either need to escape it or, possibly, you need to use a different way to get what you want there because you just can't use `%` in the script. (`basename` will strip an extension too optionally so you could invert the first two lines and use `$(basename "$i" "$extension"`)`). – Etan Reisner Apr 08 '15 at 22:26
  • @EtanReisner Thanks a lot! With escaping it works `filename="${filename%%.*}";` – rwx Apr 09 '15 at 07:45
  • File that as an answer and accept it. – Etan Reisner Apr 09 '15 at 12:38

1 Answers1

1

In Xfces user defined actions % must be escaped. So you need here to use

filename="${filename%%.*}";

instead of

filename="${filename%.*}";
rwx
  • 11
  • 2