Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically set custom folder/directory icon in Linux

In Linux, can one set a custom icon for a folder/directory as it appears in a desktop/file manager?

For example for Windows Explorer one can set a custom icon in the folder's desktop.ini file?

If so, is there a common mechanism or API function to do this (that is perhaps common among distros/desktops/file managers)?

I would like to do this from a standalone console mode program C++ or perhaps using the desktop API for KDE, gnome etc.. (also Unix CDE and OSX)

like image 579
Roger Nelson Avatar asked Jun 24 '09 01:06

Roger Nelson


3 Answers

If you are using the KDE desktop, then simply create a .directory file inside the directory.

E.g. I have a custom icon for my directory named "dev.sparc". I created this using the KDE desktop. All it does is create a file which I can view.

$ cat dev.sparc/.directory
[Desktop Entry]
Icon=applications-engineering

Et voila. That's all there is to it. If you or your users are using Gnome, this will be similar but probably subtly different. Just create an empty directory, use Gnome to set an icon, then $ ls -al in the directory to see what file it created.

like image 146
the.jxc Avatar answered Nov 20 '22 15:11

the.jxc


I was recently trying to do something similar with creating desktop shortcuts on various Linux platforms and found this post.

For more information, see the Desktop Entry Specification from freedesktop.org which describes the standard for desktop and directory shortcuts on KDE and GNOME desktops.

like image 39
drew010 Avatar answered Nov 20 '22 17:11

drew010


There is no standard way to do this across GNOME, KDE, and CDE.

like image 3
anthony Avatar answered Nov 20 '22 16:11

anthony