Change Freedesktop file icon
For the purpose of a desktop, files are given types. The type is described by a MIME string, much the same as a web page has a MIME. You know how it works—you see a ‘Text‐file’ icon, you click on it, it launches the the file in a text editor/word processor.
This article is about how to change the icon associated with a type of file. Elsewhere is another article about how to create a new mime type.
Howto change the icon associated with a mime
The idea is you name your icon after the mime‐type e.g. ‘text‐x‐garbage.svg’. You dump this specifically‐named icon in one of the icon folders, then run a cache update (yes, icon data needs to be cached). The system then associates the files with the mime‐type to the new icon.
The steps in detail…
Get an icon
Make or steal an ‘svg’ icon. If making a new icon, make something simple at 32x32 or 64x64 pixels. Leave a bit of space round the image, and lean towards gray scales, not full‐range contrast. You can always make things better when you know it works.
Name the icon
It’s the full MIME path with hyphens. The extension is the usual image type extension. For example, ’text‐html.svg’.
It is a convention to make customised/local mimetypes with an added ‘x’. This should be included in the filename. For example ‘text‐x‐garbage.svg’.
Find and choose your XDG path
Find configured Freedesktop paths,
printenv XDG_DATA_DIRS
You will see several paths. I recommend you configure at a ‘/usr/…’ relative path—see the notes below.
If you want to recognise a custom kind of file which this icon will identify
You need to create a new mime type.
Find a primary theme folder
This is where things can get messy. See the questions and advice.
Use the GUI and look up the icon theme‐name in ‘preferences’ or wherever. With the path found above, plus the subfolder ‘icons’ and the theme name, you can find the configuration folder for your theme. My theme is ‘Mint‐Y’. If you are using a variation on a theme, I recommend you try the base theme first. So, for example, if you are using ‘Mint‐Y‐Aqua’, start with ‘’Mint‐Y’. Mine is,
/usr/share/icons/Mint-Y/
Now find the ‘…/mimetypes/scalable’ directory (SVG icons are classed as ‘scalable’). If you can’t find one, see the next section,
/usr/share/icons/Mint-Y/mimetypes/scalable
Dump your ‘svg’ file in there.
Configuring a new theme folder
The above will not work in Linux Mint because there is no ‘…/mimetypes/scalable’ folder (there are folders for many PNG icons, like ‘24’ and ‘64’). You may find other folder organisations, I have.
Anyway, best to keep some organisation here, not dump at convenience (though that may work). Configure a new directory in the theme. Create,
mkdir /usr/share/icons/Mint-Y/mimetypes/scaleable
Now edit the ‘index.theme’ file to tell the cache programs to look in the new directory,
nano /usr/share/icons/Mint-Y/index.theme
Add the path to the directory list,
Directories=mimetypes/scalable,...
Then tell the config about what it finds in that folder. Put this someplace in amongst the list of path stanzas at the end of the ‘index.theme’ file (the comment lines are optional,but I like to mark a custom addition),
##### custom
[mimetypes/scalable]
Size=16
Context=Mimetypes
Type=Scalable
MinSize=8
MaxSize=512
######
Always put the size definition into the stanza, even for scalable icons—it is required.
Update cache
Now run this (for GTK. There is a KDE equivalent etc. All these utilities are based in Freedesktop code),
gtk-update-icon-cache path/to/the/theme/folder
This tool is –verbose by default, but sadly tells you little. How we need that! However, cache‐update should do it. Your icon should associate with files of the stated MIME‐type. In Mint ‘nemo’ icons will update without a browser refresh. Phew.
Questions and advice
Can you do this in userspace?
Yes, for icon placement, mime association, and extra mime‐types. However, the interactions are complex, and make your chances of initial success lower. Which is why I suggest a first attempt using scalable icons, known MIME‐types, the ‘/usr’ folders, and the base of the configured theme. As explained above.
The reason I do not expand on userspace is because you may not have a user‐configuration path for the Desktop configuration. Also, icon choosing depends on a theme inheritance chain, see other advice. The overrides can be complex. I recommend dumping in your main theme—not because it is the best solution, but because it is reliable.
What do you mean, the theme interactions can be complex?
See the main Spec for Freedesktop icons, linked below.
First, themes can inherit from each other. Here’s the list from my ‘index.theme’,
Inherits=Mint-Y,Adwaita,gnome,hicolor
So there are four possible other themes the theme code may be falling back to. Then, if the desktop is following spec, the search for an icon is not simple. It depends on the display size of the icon, then a search across alternate folders, a fuzzy match, and then possible defaults. Maybe that action should not be described as ‘complex’, but there is no feedback about the algorithm’s decisions, and we are rooting about in deeper parts of the operating system. So the decision‐making is not ‘simple’.
What’s gone wrong for you?
Oh, attachment to custom MIME‐type with a custom icon should present no decisions to make? But has failed for me, and web posts say it has failed for others. For example, I once placed the new icon in every inherited theme and it didn’t work in any of them. I tried adapting sizes in the ‘index.theme’ file. I tried adapting configs. I checked permissions. The Adwaita theme has an ominous comment,
Comment=The Only One
I tried multiple cache‐updates. That time, nothing worked until placement in the folder for the base theme.
What’s the Freedestop advice?
Freedesktop recommends placing ‘App’ icons in the ‘hicolor’ theme, which should always be present. This makes sense because a special ‘App’ icon should show in any theme, regardless. But the advice is not much help for other kinds of icons like ‘mimetype’. They may get overridden in various ways, and you may have difficulty registering the icon with the type anyway. That’s why I recommend the path above.
Why SVG?
Drop a PNG into a theme folder, and you may be viewing at a wrong size. Whereas an SVG will be configured for most sizes.
Why is this job difficult?
Good question. You may like to consider that Linux Desktops have spawned project after project to change icons, and no solution has lasted long.
References
Freedesktop icon theme spec,
https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html
Ubuntu answers,
https://askubuntu.com/questions/52138/how-do-i-change-the-icon-for-a-particular-file-type
Freedesktop icon naming spec (useful for a quick check on what is supposed to be standard),
https://specifications.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html
Archived page on how to make Tango icons (still good recommendations and the base of many Linux desktop themes),
https://web.archive.org/web/20160202102503/http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines