Plasma-changeicons does not work when activated from a scheduled script:

Hello. I use the following script to change my icons at dawn/dusk:

#!/bin/bash

if  [ $(( $(date +%H) % 19 )) -lt 6 ]; then
	plasma-apply-colorscheme Win12OSNord -platform offscreen
	/usr/lib/plasma-changeicons Colorful-Dark-Icons
else
	plasma-apply-colorscheme BreezeClassic -platform offscreen
	/usr/lib/plasma-changeicons breeze
fi

The behavior here is really bizarre: in the morning, it works flawlessly. In the evening, though, the icon change fails. No matter what I request as an icon theme, it fails and falls back to breeze. Even if I request “breeze,” it fails to respect system accent color when the switch happens. If I manually run the script in the daytime, though, it works just fine.

Hello @AidanofVT Not optimal but seems to be working.
Start at Autostart cc.sh &

#!/bin/bash
rm -f /tmp/Dark.txt /tmp/Light.txt
while true;
do
 if  [ $(( $(date +%H) % 19 )) -lt 6 ]; then
  if [ ! -f /tmp/Dark.txt ]; then
	plasma-apply-colorscheme Win12OSNord -platform offscreen
	/usr/lib/plasma-changeicons Colorful-Dark-Icons
	touch /tmp/Dark.txt
        rm /tmp/Light.txt
   fi
   elif [ ! -f /tmp/Light.txt ]; then
     plasma-apply-colorscheme BreezeClassic -platform offscreen
	 /usr/lib/plasma-changeicons Breeze
	 touch /tmp/Light.txt
         rm /tmp/Dark.txt
  fi
 sleep 60
done

Do you mean to say that you actually replicated the issue? What do you think the main mistake was in my original script? I am an amateur; I don’t know enough to see why you chose the alternate method shown.

You checked the time once maybe at login time.
If you don’t want to use cron or at then you should check the actual time periodically.
All the rest is to set colorscheme only when it is needed.

Sorry, I should have been more clear: this is already attached to an hourly cron job. So, when I first boot, no icons. Then, when night comes, I get the night icons. When day comes, I get Breeze icons without accent color. And back and forth between the night Icons and default-blue Breeze as scheduled.

I got some errors when running this script. Claude 3.7 modified it into this, which I think preserves the intent:

#!/bin/bash

# Get current hour (without leading zero to avoid octal interpretation)
current_hour=$(date +%-H)

# Check if it should be dark mode (hours divisible by 19 with remainder 0-5)
if [ $(( current_hour % 19 )) -lt 6 ]; then
  # We should be in dark mode
  if [ ! -f /tmp/Dark.txt ] || [ -f /tmp/Light.txt ]; then
    plasma-apply-colorscheme Win12OSNord -platform offscreen
    /usr/lib/plasma-changeicons Colorful-Dark-Icons
    
    # Only attempt to remove Light.txt if it exists
    if [ -f /tmp/Light.txt ]; then
      rm -f /tmp/Light.txt
    fi
    
    touch /tmp/Dark.txt
    echo "Switched to dark mode at $(date)"
  fi
else
  # We should be in light mode
  if [ ! -f /tmp/Light.txt ] || [ -f /tmp/Dark.txt ]; then
    plasma-apply-colorscheme BreezeClassic -platform offscreen
    /usr/lib/plasma-changeicons Breeze
    
    # Only attempt to remove Dark.txt if it exists
    if [ -f /tmp/Dark.txt ]; then
      rm -f /tmp/Dark.txt
    fi
    
    touch /tmp/Light.txt
    echo "Switched to light mode at $(date)"
  fi
fi
echo "Done."

The resulting behavior is exactly the same as my own script; the problem remains.

I came across a simpler scheduler than crontab.
hwatch -n 20 -x "~/42.sh"
It runs your script in every 20 secunds.

The issue is not with timing. The timing works okay. The problem is that the bash script isn’t properly modifying the icons when it fires.

With the help of AI, I somewhat narrowed the problem to something to do with the “icon cache.” Forcing a reset of that cache at the top of the script is an effective workaround:

rm -f ~/.cache/icon-cache.kcache ~/.cache/kiconcache/*
kbuildsycoca5 --noincremental

If this inspires anyone to guess at a more specific explanation of the problem, let me know!