Ubuntu – How to set emblems in Thunar without the GUI

thunar

I would like to add emblems to a file in Thunar using a script, but I can't find any documentation on this.

Is it possible to do this? And if so, how?

The same question was asked here, but they mention a ~/.cache/Thunar/metafile.tdb file which does not exist on my system. I think that question and the answer are outdated.

Best Answer

Thunar, since version 1.6, has started using the gvfs-metadata daemon to store metadata. The metadata is stored in ~/.local/share/gvfs-metadata, however you can't read it from the files (it's stored in some binary format I think). In order to read metadata you use the gvfs-info command like this:

gvfs-info -a metadata:: /some/location  

Which will print out the metadata of /some/location.

If you want to change metadata you can use the gvfs-set-attribute command like this:

gvfs-set-attribute /some/location -t stringv metadata::mdtype value  

/some/location is the location of the file/folder whose metadata you want to edit, -t stringv tells the command to expect string input, mdtype sets the type of metadata you want to change (e.g. emblems) and new value sets value as the metadata for mdtype. For example:

gvfs-set-attribute Downloads -t stringv metadata::emblems emblem-default  

Gives the Downloads folder the default emblem.

Set the value to none to remove emblems. You will have to restart the file manager to see the changes.


I wrote a small script that allows you to change the emblem of more than one folder/file at a time:

run() {    
cd # make sure we're in the home directory
echo 'What emblem do you want to apply?'
read emblem

if ! [ -z $emblem ]; then
    for i in $@
    do
        echo 'Changing stuff...'
        $(gvfs-set-attribute $i -t stringv metadata::emblems $emblem)
    done
    echo 'Done!'
else
    echo 'Emblem must be specified! Exiting...'
    exit  
fi
}

init() {

if [[ -z $@  ]]; then
    echo "No arguments provided"
else   
    run $@
fi
}

init $@  

Sources: