1

As Unix Ubuntu does not support a natural scrolling and tap touchpad click I created simple script for enabling those options. As I got tired of executing it every time I reboot the laptop I wanted to add script to init.d but somehow it does not execute. Please find the code below:

#!/bin/bash
DEV="$(xinput list | grep Touchpad | grep -o '=[0-9][0-9]' | grep -o '[0-9][0-9]')"
TAP="$(xinput --list-props $DEV | grep 'Tapping Enabled (' | grep -o '[0-9][0-9][0-9]')"
SCROLL="$(xinput --list-props $DEV | grep 'Natural Scrolling Enabled (' | grep -o '[0-9][0-9][0-9]')"

xinput set-prop $DEV $TAP 1
xinput set-prop $DEV $SCROLL 1

I have done the following 1:

Move file to init.d
Sudo chmod a+x /etc/init.d/touchpad.sh
update-rc.d touchpad.sh defaults

2:

Open cronetab
@reboot /directory/touchpad.sh

Both methods does not work but script runs with:

sudo /etc/init.d/touchpad.sh start

Is there something I'm missing?

Thanks

1
  • 2
    Do not post solutions in "edits". There is the answer form for that. Commented Aug 11, 2020 at 11:21

2 Answers 2

2

I would check the path, especially for cron, though I'm not sure about init.d. You also could look at creating a service unit for systemd instead of using init.d since you're using a version of Ubuntu that uses it.

For any of it, you should look into setting either absolute paths for executables in your script or making sure the system path gets set the way you want it. If you're not sure where an executable lives you can use which xinput (or any other executable) at the command prompt and it should tell you where it lives. In my case on my Ubuntu 18.04 system xinput lives at /usr/bin/xinput which isn't included in the standard cron shell. You can also find out what your system path is by typing echo $PATH at the command line. Usually the path is set somewhere in your ~/.bashrc file along with other shell settings.

You can also set that path at the top of the script (or in your crontab file). If you want to use cron, I recommend looking here for how to set some options for cron, particularly the path. The article also goes over the defaults cron uses when it executes.

I'm not that familiar with init.d so I can't speak to that, but if you want to use systemd to run your script at startup this is a good resource on how you'd create a service unit for systemd to execute.

If you're interested in the difference between systemd and init.d you can look here.

Further, if the above doesn't work try to include some output redirection for your script, it could be executing but failing to work as intended. Also if you create a systemd service unit you can do output redirection this way.

4
  • 1
    Thanks for help and reminding me of services. However after changing the paths to absolute, creating a service, it wouldn't start anyway. I just wonder what else can cause this. [Unit] Description=Touchpad [Service] Type=simple ExecStart=/home/huu/Documents/touchpad.sh [Install] WantedBy=multi-user.target That's what I have added to the file. It does not start even with the systemctl start command.
    – Huu
    Commented Aug 7, 2020 at 9:22
  • 1
    Did you have some kind of output read directions so you can see if it is running, but the commands are failing? I also wonder because I’m not entirely sure, does your script require that you be fully logged in and have the graphical user interface up to work? Commented Aug 8, 2020 at 13:32
  • 1
    I checked the output and it seems that systemctl does not have access to that command. When I start service all echos are written into my file but the command for listing does not give any output. /usr/bin/xinput list >> /home/huu/Documents/touchpad.txt. On the contrary when I run the script from terminal everything gets executed and output is written to the file.
    – Huu
    Commented Aug 11, 2020 at 9:52
  • 1
    Found a solution for it, gonna post it in the edit
    – Huu
    Commented Aug 11, 2020 at 11:06
1

Solution

So I dug a little bit more and it seems that X Server is executed after the GUI starts. Check those links: https://unix.stackexchange.com/questions/360537/cant-run-application-that-depends-on-x-as-a-systemd-service https://unix.stackexchange.com/questions/42611/how-can-i-run-a-script-that-starts-before-my-login-screen/42621#42621

I used cat /etc/X11/default-display-manager to get my display manager name and used wiki to set up the startup script: https://wiki.ubuntu.com/LightDM

Everything left to do was to add session-setup-script=/home/huu/Documents/touchpad.sh in /usr/share/lightdm/lightdm.conf.d/50-unity-greeter.conf file according to the wiki page.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .