Ubuntu – Add script to System -> Preferences -> Startup Applications

scriptsstartupstartup-applications

I want to run a script that changes the mapping of my keyboard from the startup applications. The script is in my home folder and it has permissions 755.
I've created a new entry in System -> Preferences -> Startup Applications and tried the following commands:

/bin/bash /home/myuser/myscript.sh
/sbin/sh /home/myuser/myscript.sh
/home/myuser/myscript.sh

None of them worked. The same commands work fine when I run them from a terminal manually.

I know of other ways to run a script at startup, but I want to know why is this method not working for me.

Best Answer

Startup scripts, related to keyboard- or touchpad settings, or include wmctrl or xrandr commands often need "a little break" before running. If they run too early, before the desktop is fully loaded, they either break or "miss their target".

To solve that, you need to add:

/bin/bash -c "sleep 10 && /home/myuser/myscript.sh"

to your startup applications. Possibly you need to play a little with the sleep 10 value to optimize.

Note

Probably the script exists of only one or two commands, you could include them in your startup command, with the same syntax. That way you do not need a separate script.

Related Question