Score:0

Script Isn't Working at Reboot

es flag

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!

hr flag
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?](https://askubuntu.com/questions/747399/is-crontabs-reboot-entry-triggered-after-x-has-started)
es flag
@steeldriver worked like a charm! Thank you so much!
hr flag
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
es flag
@steeldriver you are right, it is much simpler than what I was doing! Thanks again!
Score:0
cc flag

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.

es flag
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?
cc flag
./yourscript should be all you need in the .profile, etc.
es flag
I get it now. I'll try it, thanks!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.