Custom icon for a specific file type in Nautilus (Ubuntu 22.04, GNOME v42.9)

My system is Ubuntu 22.04.4; GNOME Shell v42.9

The application is HomeBank, installed via flatpak. The files have an extension .xhb. I want to associate the icon of this application to this file type.

I found the application logo files under /usr/share/icons/hicolor/ZxZ/apps/homebank.png. The available sizes (= Z) are 16, 22, 24, 32, 48, 256. There was no scalable .svg icon, but I have built one.

A Google search brought up this answer from AskUbuntu. I’ll list what I did step by step. The OP wanted a custom icon for application/x-hwp files. I want it for application/x-homebank files.

1. Edited /etc/mime-types to add the line:

application/x-homebank        xhb

I confirmed the MIME type by right-clicking on a .xhb file β†’ Properties in Nautilus.

2. Created an mimetypes/ directory under /usr/share/icons/gnome/scalable/.

3. Copied the scalable icon as below:

sudo cp /path/to/icon/application-x-homebank.svg /usr/share/icons/gnome/scalable/mimetypes/

4. Restarted GNOME with Alt + F2 β†’ r.

Icons did not change in nautilus.

Found another answer to a similar question on AskUbuntu again. The OP wanted to add custom icons for MATLAB files and figures. Here’s what I did:

1. Created the following XML file ~/homebank.xml:

<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
  <mime-type type="application/x-homebank">
    <comment>Homebank data file</comment>
    <glob pattern="*.xhb"/>
    <icon name="application-x-homebank"/>
  </mime-type>
</mime-info>

This format is also written in the docs of xdg-mime command.

2. Ran the following:

sudo xdg-mime install --novendor ~/homebank.xml

This added the following file in /usr/share/mime/application/x-homebank.xml:

<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/x-homebank">
 <!--Created automatically by update-mime-database. DO NOT EDIT!-->
 <comment>Homebank data file</comment>
 <glob pattern="*.xhb"/>
 <icon name="application-x-homebank"/>
</mime-type>

This probably shows that xdg-mime worked fine.

3. Painstakingly installed the icons, for each of the available sizes listed above, as follows:

sudo xdg-icon-resource install --novendor --noupdate --context mimetypes --size 48 homebank_48.png application-x-homebank

The above step also created symlinks. The directory structure of /usr/local/share/icons/hicolor/ is like this:

β”œβ”€β”€ 16x16
β”‚   β”œβ”€β”€ apps
β”‚   β”‚   └── ...
β”‚   └── mimetypes
β”‚       β”œβ”€β”€ application-x-homebank.png
β”‚       └── gnome-mime-application-x-homebank.png -> application-x-homebank.png
β”œβ”€β”€ 22x22
β”‚   └── mimetypes
β”‚       β”œβ”€β”€ application-x-homebank.png
β”‚       └── gnome-mime-application-x-homebank.png -> application-x-homebank.png
β”œβ”€β”€ 24x24
β”‚   β”œβ”€β”€ apps
β”‚   β”‚   └── ...
β”‚   └── mimetypes
β”‚       β”œβ”€β”€ application-x-homebank.png
β”‚       └── gnome-mime-application-x-homebank.png -> application-x-homebank.png
β”œβ”€β”€ 256x256
β”‚   β”œβ”€β”€ apps
β”‚   β”‚   β”œβ”€β”€ ...
β”‚   └── mimetypes
β”‚       β”œβ”€β”€ application-x-homebank.png
β”‚       └── gnome-mime-application-x-homebank.png -> application-x-homebank.png
β”œβ”€β”€ 32x32
β”‚   β”œβ”€β”€ apps
β”‚   β”‚   └── ...
β”‚   └── mimetypes
β”œβ”€β”€ 48x48
β”‚   β”œβ”€β”€ apps
β”‚   β”‚   └── ...
β”‚   └── mimetypes
β”‚       β”œβ”€β”€ application-x-homebank.png
β”‚       └── gnome-mime-application-x-homebank.png -> application-x-homebank.png
└── scalable
    └── mimetypes
        β”œβ”€β”€ application-x-homebank.svg
        └── gnome-mime-application-x-homebank.svg -> ./application-x-homebank.svg

The last directory scalable/ was added by me manually because xdg-icon-resource doesn’t support scalable icons by default. I did this with:

sudo mkdir scalable
cd scalable
sudo mkdir mimetypes
cd mimetypes
sudo cp ~/path/to/scalable_icon.svg ./application-x-homebank
sudo ln -s ./application-x-homebank.svg ./gnome-mime-application-x-homebank.svg

4. Then ran

sudo xdg-icon-resource forceupdate

5. Restarted Gnome shell.

Nothing. Absolutely no change.

Came across this question on Unix-Linux SE, decided to give it a go. Ran the following:

update-mime-database ~/.local/share/mime
sudo update-mime-database /usr/share/mime/
update-icon-caches ~/.local/share/icons
sudo update-icon-caches /usr/share/icons/
sudo update-icon-caches /usr/local/share/icons/

No change.

Also did:

sudo cp ./application-x-homebank.svg /usr/share/icons/gnome/scalable/mimetypes/
sudo gtk-update-icon-cache /usr/share/icons/gnome/ -f
sudo gtk-update-icon-cache /usr/share/icons/hicolor/ -t
sudo gtk-update-icon-cache /usr/local/share/icons/hicolor/ -t

but in vain.

Also tried logging out and in between each of the sections above. Rebooted too. But yeah, the issue persists.

I am at a loss at this point. If anyone knows a way to make this work, I would be grateful.

What does gio info -a standard::content-type,standard::fast-content-type,standard::icon say for one of your .xhb files?

uri: file:///home/some-user/Expenses.xhb
local path: /home/some-user/Expenses.xhb
unix mount: /dev/sda2 / ext4 rw,relatime,errors=remount-ro
attributes:
  standard::icon: application-x-homebank, application-x-generic, application-x-homebank-symbolic, application-x-generic-symbolic
  standard::content-type: application/x-homebank
  standard::fast-content-type: application/x-homebank

What icon theme do you use? Maybe the fallback prioritizes the generic icon name in the current theme over the more specific one in an inherited theme.

1 Like
dconf read /org/gnome/desktop/interface/gtk-theme

returns 'Yaru-blue-dark'.

But woah, I changed the icon theme to Gnome in the tweaks tool, and now the icons are exactly what I want! The fix was that simple?!

Now I need to find a way to make this work in Yaru-blue-dark, if that is, at all, possible.

Thanks for your help, Sebastian!

Edit: Quite obviously, creating an icon in /usr/share/icons/Yaru-blue-dark/scalable/mimetypes/application-x-homebank.svg (because my icon theme is Yaru-blue-dark) fixed the issue; the .xhb files now have the icon that I want.

1 Like