How to change the icons of multiple files from terminal?

I would like to change the icons of multiple files from terminal.
Not launcher icons, but the default icons for filetypes, based on the file endings.
How to acheive this task?


"emblems" are stored as binaries in directory ~/.local/share/gvfs-metadata.

So you need gvfs-bin Install gvfs-bin for this to be able to extract them and save them. Oh and there is one file per partition/volume/directory/file (to make things worse).

To get info on an emblem you can use:

gvfs-info -a metadata::emblems {filename|folder}

To set an {icon} for a {filename} or {folder} you use:

gvfs-set-attribute -t stringv {filename|folder} metadata::emblems {icon}

Example:

I created folders 1, 2, 3, 4 in ~/Music.

im1

Commands inside the terminal of the image:

gvfs-set-attribute 1 metadata::custom-icon file:///usr/share/pixmaps/gnome-log.png

gvfs-set-attribute 2 metadata::custom-icon file:///usr/share/pixmaps/gnome-spider.png

Change the 1 and 2 to an existing video file or any other actual file and it should work the same.

and F5 updates the bottom panel.

As you can guess from directory 3 and 4 you will need to do this for every file you want this for.

Here's a script that walks through a directory and sets a PNG that resides in the folder as the folders emblem (basically this mimics Windows method of using folder.png as the emblem of the directory above it).

#!/usr/bin/python

import os
from os.path import join

cwdir = str(os.popen('pwd').readline()).replace('\n','')

for root, dirs, files in os.walk(cwdir):
    for name in files:
        if name.lower().find('.png') != -1:
            os.system('gvfs-set-attribute "'+root+'" metadata::custom-icon "'+name+'"')

You might be able to change this into your own version that includes files.

usage of script at own risk