Override the .desktop file for snap applications (Ubuntu)

December 29, 2020

As of 2021, apps installed with the snap package manager (Ubuntu) save their .desktop files in a specialized folder, which means you won’t find them in the usual places. A particular use case of overriding the .desktop file is to change the icon of any snap app you install on your system.

These files are located in /var/lib/snapd/desktop/applications, here’s a dump of my current list of files inside that folder:

/var/lib/snapd/desktop/applications
β”œβ”€β”€ foliate_foliate.desktop
β”œβ”€β”€ intellij-idea-ultimate_intellij-idea-ultimate.desktop
β”œβ”€β”€ mimeinfo.cache
β”œβ”€β”€ obs-studio_obs-studio.desktop
β”œβ”€β”€ postman_postman.desktop
β”œβ”€β”€ snap-store_snap-store.desktop
β”œβ”€β”€ snap-store_ubuntu-software.desktop
└── snap-store_ubuntu-software-local-file.desktop

In my case, I have installed these snap apps: Foliate, IntelliJ, OBS Studio, and Postman. Notice how all the apps follow a pattern: app-name_app-name.desktop. If you wanted to override any of these files, all you have to do is create a copy (with the same name) inside ~/.local/share/applications.

To exemplify this process, I’ll add Postman to my Ubuntu dock and change the icon snap provides for one I like a lot from an icon theme called Zafiro. Here’s the original file:

/var/lib/snapd/desktop/applications/postman_postman.desktop

[Desktop Entry]
X-SnapInstanceName=postman
Type=Application
Name=Postman
Icon=/snap/postman/130/usr/share/Postman/resources/app/assets/icon.png
Exec=env BAMF_DESKTOP_FILE_HINT=/var/lib/snapd/desktop/applications/postman_postman.desktop /snap/bin/postman %U
Categories=Development;
MimeType=x-scheme-handler/postman
Terminal=false

All I will do is change it’s icon by replacing the line that starts with Icon= with the path of the icon I actually want to display:

~/.local/share/applications/postman_postman.desktop

...
Icon=/usr/share/icons/zafiro/apps/scalable/postman.svg
...

And once you save the file, after a few seconds you’ll see the changed icon replace the old one:

replacement


Written by Luis Lopez , a software developer (29 years old) who loves movies and classic rock. Mail me at hello@kozmicluis.com! Or follow me on Twitter.