Xfce Forum

Sub domains
 

You are not logged in.

#1 2026-06-15 15:16:12

bigbadaboum
Member
Registered: 2022-12-22
Posts: 28
LinuxFirefox 114.0

[SOLVED] Can Thunar Custom Action run .sh scripts?

I'm trying to convert all the WebP files in a folder to JPEG files using a Thunar custom action.

#!/bin/bash

for f in ./*.webp; do
    if [ -f "$f" ]; then
        basefilename="${f%.*}"
        newfilename="${basefilename}.jpg"
        if [ ! -f "$newfilename" ] ; then
            printf "Converting %s to %s " "$f" "$newfilename"
            convert -quality 55 "$f" "$newfilename"
            if [ -f "$newfilename" ]; then
            rm $f
            printf "...... Done!! \n"
            fi
        else
            printf "\n !!!File $s already exists !!!\n" $newfilename
            continue
        fi
    fi
done   
exit 0

source: https://www.thechubbyengineer.com/compu … es-to-jpg/

Can you help me?

Last edited by bigbadaboum (2026-06-15 19:16:40)

Offline

#2 2026-06-15 17:40:19

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 12,644
LinuxFirefox 151.0

Re: [SOLVED] Can Thunar Custom Action run .sh scripts?

Thunar custom actions work on mimetypes, like folder or image/webp. This means if you want to work on folders containing webp images and webp images directly, you'll need two separate custom actions.

Custom Action #1 - folders containing webp images

  1. Create a script with the following content (and make it executable):

    #!/usr/bin/env bash
    
    for F in $@; do
            for f in "$F"/*.webp; do
                    basefilename="${f%.*}"
                    newfilename="${basefilename}.jpg"
                    convert -quality 55 "$f" "$newfilename"
                    rm "$f"
            done
    done
  2. In the custom action, set the command to point to this script followed by "%F"

  3. On the appearance tab, select "Directories"

  4. To make it work, right-click on one or more directories containing webp files and select this custom action.


Custom Action #2 - webp image files

  1. Create a script with the following content (and make it executable):

    #!/usr/bin/env bash
    
    for f in $@; do
            basefilename="${f%.*}"
            extension="${f##*.}"
            newfilename="${basefilename}.jpg"
            if [ "$extension" == "webp" ]; then
                    convert -quality 55 "$f" "$newfilename"
                    rm "$f"
            fi
    done
  2. In the custom action, set the command to point to this script followed by "%F"

  3. On the appearance tab, select "Images"

  4. To make it work, right-click on one or more webp files and select this custom action.

Last edited by ToZ (2026-06-15 19:14:51)


Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2026-06-15 19:15:47

bigbadaboum
Member
Registered: 2022-12-22
Posts: 28
LinuxFirefox 114.0

Re: [SOLVED] Can Thunar Custom Action run .sh scripts?

Your two tutorials work perfectly for me, thank you very much.

Offline

#4 2026-06-16 07:07:20

organicode
Member
Registered: 2026-04-01
Posts: 26
LinuxFirefox 140.0

Re: [SOLVED] Can Thunar Custom Action run .sh scripts?

Congrats on solving the issue above.

Interested in the unspoken subtext of this topic. Why convert webp to jpg? Just interested to know out of curiousity, Because I thought webp has better quality for its lossy compression when compared to jpg. Assuming its a support based thing, I believe support for jpg is more widespread but i could be wrong, and dont want to assume. Just wondering if I'm missing something important (not online much these days due to modem issue).


No LLM was used in the production of this post

Offline

Registered users online in this topic: 0, guests: 1
[Bot] CCBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.020 seconds, 7 queries executed - Memory usage: 533.86 KiB (Peak: 534.84 KiB) ]