9

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.

1 Answers1

14

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:

Grumbel
  • 4,729
Seth
  • 58,122
  • @RemcoHaszing Please check my edited answer, I made an error and have now corrected it. – Seth Jan 23 '14 at 01:40
  • I wanted to know, because I wanted to write a script which sets the emblems to indicate the status of my Dropbox folders. I found out that I have to restart Thunar in order to see the newly added emblems and read this afterwards in your updated answer. Do you know whether Thunar can pick up these changes while running somehow? – Remco Haszing Jan 23 '14 at 07:31
  • @RemcoHaszing No, that's really not possible AFAIK. Thunar would have to continually poll for changes and that would take a lot of resources. I could edit the script to close all running instances of Thunar and open a new instance at your Dropbox folders, depending on what exactly you are trying to do. – Seth Jan 23 '14 at 17:47
  • Very nice script and command. This works perfectly on files and directories. However, my Dropbox folder is its own partition /dev/sda2 but it mounts at ~/Dropbox. I tried setting the emblem for ~/Dropbox but it didn't work. Any ideas? Thank you – jbrock Apr 19 '15 at 22:15
  • @jbrock Did you restart the file manager? The changes don't take affect until it is restarted. If that doesn't solve it then I'm afraid I don't know. You could try asking a new question. I'd love to help, but I currently lack the resources to test this specific issue. Sorry! – Seth Apr 19 '15 at 23:04
  • I only needed to unmount the partition. Then it worked just as the other directories and files did. Thank you so much for posting this! :) – jbrock Apr 19 '15 at 23:11
  • @jbrock I'm glad you got it working, although a little confused as to why unmounting it was necessary.. Glad it works! – Seth Apr 19 '15 at 23:17
  • @Seth: It is a bit mysterious. To remount 'sudo mount -a' immediately removed the emblem on the folder. Then I unmounted and reset it the emblem and remounted using the sidebar in Thunar. This time the emblem stayed, but when I opened the home directory in Thunar a few minutes later, Thunar had replaced it with a different emblem from the options under Properties > Emblems. Oh well, I am glad it works for the other files and directories though. – jbrock Apr 19 '15 at 23:35