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.

share|improve this question
    
Are you sure it doesn't exist? ~/.cache is a hidden file you know.. – Seth Jan 21 '14 at 19:58
    
~/.cache/Thunar/ doesn't even exist. Not even after adding an emblem to a file in Thunar. I have Thunar version 1.6.3 installed. – Remco Haszing Jan 21 '14 at 20:22
up vote 12 down vote accepted
+200

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:

share|improve this answer
    
Just the answer I was looking for. Thanks! – Remco Haszing Jan 22 '14 at 12:24
    
@RemcoHaszing Please check my edited answer, I made an error and have now corrected it. – Seth Jan 23 '14 at 1: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 7: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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.