Kev Quirk

Proudly ruining the web since 2013.

Stop Ubuntu Resetting Your Icon Theme When Toggling Dark Mode

The Papirus icon theme is my favourite - I've used it for years and it continues to work beautifully. So while I've been rebuilding my Framework 13, it was one of the first things I installed.

But there's a problem, dear reader. You see, I'm a proud light mode person, but I regularly switch to dark mode when working in the evening. However, Ubuntu has this silly bug where it switches back to the default Yaru icon theme whenever one switches between light and dark mode.

Annoying.

On my previous machine I had a cronjob running every minute that simply checked the theme and switched it to Papirus if it was Yaru. That worked fine, but wasn't the most elegant solution.

So, this time I did more research and came up with a slightly more elegant fix workaround.

How to "fix" it

Ok, it's pretty simple. It consists of a small script that runs whenever Ubuntu flips between light/dark mode, then 0.2 seconds later, switches the icon theme back.

Far from perfect, but it's better than a script that runs every minute the machine is running.

To do this, create a new script at ~/.local/bin/watch-darkmode.sh with the following contents:

gsettings monitor org.gnome.desktop.interface color-scheme | while read -r line; do
    if echo "$line" | grep -q "prefer-dark"; then
        sleep 0.2
        gsettings set org.gnome.desktop.interface icon-theme 'Papirus-Dark'
    elif echo "$line" | grep -q "default"; then
        sleep 0.2
        gsettings set org.gnome.desktop.interface icon-theme 'Papirus'
    fi
done

You need to make the script executable, so run this next:

chmod +x ~/.local/bin/watch-darkmode.sh

Next thing is create a .desktop file that tells GNOME to automatically start the script when we log in:

# Create the file
nano ~/.config/autostart/watch-darkmode.desktop

# Paste this into the nano window
[Desktop Entry]
Type=Application
Name=Watch Dark Mode
Exec=/home/YOUR-USERNAME/.local/bin/watch-darkmode.sh
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true

Remember to change YOUR-USERNAME on the Exec= line to whatever your Ubuntu username is.

That's it! Log out, and back in again, and the script should be doing it's thing in the background. So the next time you switch between light and dark mode, your fancy-pants icon theme should persist.

Reply by email

Subscribe for more!

You don't have to keep coming back here to read my latest waffle. There's a couple of way to subscribe to receive updates whenever I publish new content.

⬅ The one before
Update #2 on the Framework Saga