Because I know that a simple API call handles setting the custom folder icons in Windows, I looked for an API method to set custom folder icons in Linux.
But in this thread, I saw that there is no such a way. Also I learnt that each desktop environment has its own way to set custom folder icons. The way of KDE is clearly described there.
For GNOME I looked for a similar way; but no file is created when setting the folder's icon from the properties panel. I think there should be a registry-like file in somewhere in the user home or /etc.
I will be glad, if you kill my pain. Thanks.
Right-click on the folder and select 'Properties'. In the folder properties, click on the 'Customize' tab. From here, click on the 'Change Icon' option under the 'Folder icons' section.
Here's how to customize your Windows 7 folder icons: Step 1: Right-click on a folder you want to customize and select "Properties." Step 2: In the "Customize" tab, go to the "Folder icons" section and click the "Change Icon" button. Step 3: Choose one of the many icons listed in the box then click OK.
I finally figured out how to do this! Here's a Python script that works in the standard Gnome environment:
#!/usr/bin/env python
import sys
from gi.repository import Gio
if len(sys.argv) not in (2, 3):
print 'Usage: {} FOLDER [ICON]'.format(sys.argv[0])
print 'Leave out ICON to unset'
sys.exit(0)
folder = Gio.File.new_for_path(sys.argv[1])
icon_file = Gio.File.new_for_path(sys.argv[2]) if len(sys.argv) == 3 else None
# Get a file info object
info = folder.query_info('metadata::custom-icon', 0, None)
if icon_file is not None:
icon_uri = icon_file.get_uri()
info.set_attribute_string('metadata::custom-icon', icon_uri)
else:
# Change the attribute type to INVALID to unset it
info.set_attribute('metadata::custom-icon',
Gio.FileAttributeType.INVALID, '')
# Write the changes back to the file
folder.set_attributes_from_info(info, 0, None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With