I wanted to ask questions before I post a possible answer but I don't have enough rep for that so here goes many assumptions and few possibilities.
I assume you are using X11 and not Wayland. Look for a
Xsession or a
xinitrc file in
/etc/X11/xinit/. If you have one edit it using
nano or whatever floats your boat using:
sudo nano /etc/X11/xinit/xinitrc
for example and either add the content of your script there if it is concise enough or execute your script from there by adding:
#!/bin/sh is at the top of both your script and
Xsession file and that the file is executable by doing
sudo chmod +x xinitrc, if you have
xinitrc for example.
xinitrc in my home directory which I use so maybe you also have one or can create one(?) But then I'm not using KDE so it might not work for you. I also have one at
/etc/X11/xinit/ which I don't edit.
Then edit or create the file at
/etc/sddm.conf if it does not exist and add the following to it:
xinitrc. Maybe you could rather point it to one in your home directory? I'm not knowledgeable enough to be 100% sure. If there is already an
[X11] block just add the line to it, don't add a second
This should run your script after logging in using SDDM which is usually KDE's display manager (the thing with your username and password when logging in). You could also use
DisplayCommand instead of
SessionCommand and then point it to
/etc/sddm/Xsetup but it might not run after just logging out and back in, it will run after starting the display manager(i.e. a system restart), but I don't know if it actually restarts after logging back in.
If this was not helpful, I am sorry, here are the documentation I read which lead me to the solutions I provided which you can also use and I am very sure that you will find a solution out of them: