0

In this thread Temporarily Disable Touchscreen I asked how could I disable my HP touchscreen. By trial and error, and using the command

xinput --list

I was able to identify which device was the touchscreen and by typing

xinput disable id

being the id the device's actual number, I can disable the touchscreen.

The problem is that I have to do this every time I turn on my pc. Furthermore, depending if I turn on my computer with the mouse or not, the touchscreen changes its id.

I want to write a script that disables the touchscreen automatically every time I turn on the laptop so I need to take this in account. In the script I wrote

cd /home/user/Desktop/touchscreen_ids

xinput --list | grep "ELAN" | grep "slave  pointer" > id.txt

(the first command goes to this particular folder and the second writes the following text in txt file

⎜   ↳ ELAN2514:00 04F3:2AF4                     id=9    [slave  pointer  (2)]

). Then, still in the same script I wrote

sed -i 's/id=/\nid=/g' id.txt

sed -i 's/\[/\n\[/g' id.txt

cat id.txt | grep "id=" > iso_id.txt

sed -i 's/id=//g' iso_id.txt

touchscreen_id=$(cat iso_id.txt)

xinput disable $touchscreen_id

This works well when I run the script. However, using the cron tab @reboot option, when I turn on the pc, it creates the txt files but they are empty and the touchscreen is enabled.

Do you guys have any clue about what's going on here? I am not very experienced with Linux or the command line, so please try to keep it simple.

Thank you in advance!

4
  • 2
    This is the kind of thing that's probably better done via your desktop's Startup Applications - see Is crontab's @reboot entry triggered after X has started? Nov 30, 2022 at 16:34
  • @steeldriver worked like a charm! Thank you so much! Nov 30, 2022 at 16:55
  • Happy to help - btw you shouldn't need to jump through so many hoops to get the device ID - something like xinput list --id-only '<name-of-device>' should return it directly Nov 30, 2022 at 17:12
  • @steeldriver you are right, it is much simpler than what I was doing! Thanks again! Dec 1, 2022 at 9:51

1 Answer 1

0

cron jobs' environment is not your own, so use one of the mechanisms bash supplies to run your script. From the bash man page:

executes /etc/profile, if that file exists.  After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,

Run your script from .bash_login (or one of the others). .profile was the traditional place, which would work with some non-bash shells.

3
  • You are saying that I need to type the path to the script in one of the above options and that would run my scripts every time I turned on my pc? Nov 30, 2022 at 16:50
  • ./yourscript should be all you need in the .profile, etc.
    – ubfan1
    Nov 30, 2022 at 17:11
  • I get it now. I'll try it, thanks! Dec 1, 2022 at 9:55

You must log in to answer this question.

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