Ubuntu – How to run a sh script targeting X11-settings on login?


The gui-based controls for mouse acceleration do not suffice to tame my mouse, so I am correcting this by running:

xinput set-prop 10 "Device Accel Constant Deceleration" 2.9

This script has the desired effect (every time) when run manually from the terminal. However I have yet to find a way to run it on each login. Attempts to have it execute through rc.local or using the script launching options in the system settings have both remained fruitless.

Do you have any suggestions of what else I could try? Should I modify X11 config files directly? Several posts related to this topic advised against doing so.

Best Answer

One way is to use a cron job with the reboot directive which will run at every system's start (and reboot).

To do so:

  • Issue sudo crontab -e to enter a cron job to root's crontab
  • In a new line enter @reboot xinput set-prop 10 "Device Accel Constant Deceleration" 2.9 2>&1 >> /var/log/my_xinput.log

If the job is not running, you might want to point the full path to the xinput command.

By saying the full path to the command (xinput) i mean, that cron need to know where to find the executable - script that needs to run. This can be done either by:

  • pointing cron to the full path of what needs to be executed, for example I have a script located at ~/bin/myscript.sh; to be sure that cron knows where to find my script, I must enter it's full path to the cronjob, that is /home/username/bin/myscript.sh.
  • Or by setting environment variables at the crontab file and before my cronjob, such as:

SHELL=/bin/sh to specify which shell to use PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/home/username/bin note the last entry, etc

For your problem try:

/usr/bin/xinput set-prop 10 "Device Accel Constant Deceleration" 2.9

Finally you may want to check this references about Cron: