Nautilus changing dim and color for hidden folders/files - extension

For those who stay in Nautilus and have different dim and color for hidden folders/files, you can try this extension.

  1. create a file ~/.local/share/nautilus-python/extensions/hidden-dim.py
  2. copy this and save
import gi
gi.require_version('Nautilus', '4.0')
gi.require_version('Gtk', '4.0')
from gi.repository import Nautilus, GObject, Gtk, GLib

def walk_and_dim(widget):
    if isinstance(widget, Gtk.Label):
        text = widget.get_text()
        if text.startswith('.') and len(text) > 1:
            # Couleur sur le label
            widget.set_markup(f'<span foreground="#c0bfbc">{GLib.markup_escape_text(text)}</span>')
            # Opacité sur le parent cell (icône + label)
            parent = widget.get_parent()
            for _ in range(10):
                if parent is None:
                    break
                parent_name = type(parent).__name__
                if any(x in parent_name for x in ['ViewCell', 'FlowBoxChild', 'GridCell', 'Thumbnail', 'CanvasItem']):
                    parent.set_opacity(0.6)
                    break
                parent = parent.get_parent()

    child = widget.get_first_child()
    while child:
        walk_and_dim(child)
        child = child.get_next_sibling()

class HiddenFileDimmer(GObject.GObject, Nautilus.MenuProvider):
    def __init__(self):
        GLib.timeout_add(500, self._tick)

    def _tick(self):
        for window in Gtk.Window.list_toplevels():
            if 'Nautilus' in type(window).__name__:
                walk_and_dim(window)
        return True

    def get_file_items(self, files):
        return []

    def get_background_items(self, folder):
        return []
  1. relaunch nautilus : nautilus -q && nautilus &
  2. you can change the text color here
widget.set_markup(f'<span foreground="#c0bfbc">{GLib.markup_escape_text(text)}</span>')

and the opacity here

parent.set_opacity(0.6)

when you edit thr script think to stop and relaunch nautilus
nautilus -q && nautilus &

this isn't perfect but it work for me

Or if you prefer another script to replace the first who change the opacity for the folder and file icon only

import gi
gi.require_version('Nautilus', '4.0')
gi.require_version('Gtk', '4.0')
from gi.repository import Nautilus, GObject, Gtk, GLib

def find_label_text(widget):
    if isinstance(widget, Gtk.Label):
        return widget.get_text()
    child = widget.get_first_child()
    while child:
        result = find_label_text(child)
        if result:
            return result
        child = child.get_next_sibling()
    return None

def find_picture(widget):
    if isinstance(widget, Gtk.Picture):
        return widget
    child = widget.get_first_child()
    while child:
        result = find_picture(child)
        if result:
            return result
        child = child.get_next_sibling()
    return None

def walk_and_dim(widget):
    name = type(widget).__name__

    if name in ('NautilusNameCell', 'NautilusGridCell'):
        label_text = find_label_text(widget)
        if label_text and label_text.startswith('.') and len(label_text) > 1:
            picture = find_picture(widget)
            if picture:
                picture.set_opacity(0.35)
        return

    child = widget.get_first_child()
    while child:
        walk_and_dim(child)
        child = child.get_next_sibling()

class HiddenFileDimmer(GObject.GObject, Nautilus.MenuProvider):
    def __init__(self):
        GLib.timeout_add(500, self._tick)

    def _tick(self):
        for window in Gtk.Window.list_toplevels():
            if 'Nautilus' in type(window).__name__:
                walk_and_dim(window)
        return True

    def get_file_items(self, files):
        return []

    def get_background_items(self, folder):
        return []


here you can change the opacity

 picture.set_opacity(0.35)
3 Likes

Thank you very much, I'll try that next days. Can the extension be adapted for use with Thunar?

Does the extension only work in gnome or also in XFCE?

Edit: In Nautilus it worked. The .css file for Thunar didn't work.

It work on Gnome and for Nautilus, I really don't know how Thunar work and also XFCE.
But Thunar already have this option by design or maybe I'm wrong.
If Thunar accept python extensions maybe it could be modified for, but it's out of my competence.

Yes, thunar has this function, but the dimming in light themes is very low.

You can install the thunar python plugin for python extensions.

you can try this but with no guarantee: create or modify ~/.config/gtk-3.0/gtk.css and add this line
.dim-label { opacity: 0.35; }
I don't know if it could work...
restart thunar

Can the text for the folders/files stay the same as before without dimming/fading in Nautilus?

Sorry I don't understand your question

I can´t read the text anymore:

The text of the hidden folders/files is washed out now.
The text color is set to #000000.

replace with this

.dim-label { 
  opacity: 0.35;
  color: shade(@theme_fg_color, 0.5);
}

I was referring to your Nautilus extension.
You set the opacity for icon and label and my question is if I can only set an opacity for the icon and not for the label.

I can now read the text (probably I changed the opacity too much while playing around with the value or nautilus was not loaded correctly after changing your text color for dark theme to black color), but I'd prefer a normal black text.

The .css file for Thunar didn't work.

You an try the second script :wink:

It worked, great :grinning_face: I really appreciate that you adapted the script especially for me! Now everything is good readable.

1 Like

My pleasure, it was harder but I'm glad making it work :wink:

1 Like