Help starting a sh script at startup as user

I need this bash script to start automatically at startup, as my user, not as root, because otherwise it won’t work.

#!/bin/sh
rpl='key <CAPS> \{ repeat=no, type\[group1\]=\"ALPHABETIC\", symbols\[group1\]=\[ Caps_Lock, Caps_Lock \],actions\[group1\]=\[LockMods\(modifiers=Lock\),Private\(type=3,data\[0\]=1,data\[1\]=3,data\[2\]=3\) \] \}'

# Create copy of kb description
xkbcomp -xkb $DISPLAY keyboardmap

# Replace CAPS
sed -i "s/key <CAPS>[^;]*/$rpl/" keyboardmap

# Apply
xkbcomp keyboardmap $DISPLAY

# Remove temp file
rm keyboardmap

It solves a problem that when you disable caps lock too fast you get stuff like AA Or HEllo or LInux. (First letter after disabling caps lock turns out still a capital, because there’s a delay.)

It comes with a service that supposedly you put in /etc/systemd/system

It’s this:

#

[Unit]
Description=Run caps lock fix

[Service]
Type=oneshot
#Especificar la carpeta donde estará el archivo capslock.sh
ExecStart=/bin/sh -c "/home/afoh/Documentos/Linux Caps Lock Fix/capslock.sh"

[Install]
WantedBy=multi-user.target

But it runs as root, and thus it ends up not working, it works best as my user.

So, I need a way to run that bash script at startup as my user, if possible preserving all my user variables, like working directory and such, so that the keyboardmap file is created there and removed once done, otherwise the file isn’t even created.

How can I do this?

There are a bunch of examples on the web, but I like this simple article:

As much as I tried using that article, the variables just didn’t work right and the keyboard map file was not created. I only tried the first method though.

So instead I created a .desktop icon that links to the sh script and then placed it in ~/.config/Autostart to start it up with KDE. It can also be done from KDE Settings → Autostart, and it works just right.

Lol Im not a fan of giving myself a “solutioned” mark but it seems this fixed it.

Do you mean when that user logs in in the GUI? Then it depends on your Desktop Environment, but most of them have the feature of configuring things to be run at starting the desktop.

Well after a GUI loads the script can be autorun by user and the functionality remains

Sorry, I do not understand what you want to say with this.

Did you find the way to KDE > Systemsettings > Work Space > Startup and Closedown > Autostart (I translate from my Dutch desktop, thus you may see a different wording)?

Did you manage to Add a call to your script there? Ad did this do what you want to achieve?

Yeah thats what I did

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.