Hi all! Not good at doing any writing code an was hoping someone could help me with this. If I want to turn off my laptop touchpad I do this at the terminal.
xinput --list | grep GlidePoint (To get the ID number of my touchpad)
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=13 [slave pointer (2)]
export DISPLAY=:0
xinput set-int-prop 14 "Device Enabled" 8 0
(I have to edit the ID number because it will change on a shutdown/startup)
How can a script be done to find the correct ID of my touchpad and run this from a command file?
Thanks
Script to turn off laptop touchpad
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Script to turn off laptop touchpad
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Script to turn off laptop touchpad
Create a file as follows (you can just use gedit / Text Editor from the menu):
For example, call it "Disable-GlidePoint" or something. Then right-click it, properties, permissions, and set to allow it for executing.
Code: Select all
#!/bin/bash
# Check if GlidePoint can be found
MATCHES=$(xinput --list | grep GlidePoint | wc -l)
# Check exactly one match was found
if [[ $MATCHES != 1 ]]; then
zenity --error --text="xinput lists no GlidePoint" --title=${0}
exit 1
fi
# Get the ID of the GlidePoint
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | sed 's/ .*$//g')
# Check the match is not zero length
if [[ ${#ID[0]} = 0 ]]; then
zenity --error --text="couldn't find id of GlidePoint" --title=${0}
exit 1
fi
# Disable the GlidePoint
export DISPLAY=:0
xinput set-int-prop $ID "Device Enabled" 8 0
# Check if xinput had an error
if [[ $? != 0 ]]; then
zenity --error --text="xinput failed disabling GlidePoint" --title=${0}
exit 1
fi
Re: Script to turn off laptop touchpad
Thanks Vincent! I can't get the code to run. It bombs out at ...
bill@bill-TOSHIBA-NB205 ~ $ xinput set-int-prop $ID "Device Enabled" 8 0
Invalid format 0
All the rest of the code seems to run without any errors,
bill@bill-TOSHIBA-NB205 ~ $ xinput set-int-prop $ID "Device Enabled" 8 0
Invalid format 0
All the rest of the code seems to run without any errors,
Re: Script to turn off laptop touchpad
Well, I had to take a few guesses from the output you shared Somehow the ID is not getting grepped correctly.
Please do the following:
And then open the file "output" on your desktop, and share the contents here in a Code block (use the Code button located at the top right of the text field when you reply, and paste the contents of the output file between the code tags).
Please do the following:
Code: Select all
xinput --list | grep GlidePoint >> ~/Desktop/output
xinput --list | grep GlidePoint | sed 's/^.*id=//g' | sed 's/ .*$//g' >> ~/Desktop/output
Re: Script to turn off laptop touchpad
Code: Select all
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=13 [slave pointer (2)]
13 [slave
Re: Script to turn off laptop touchpad
Okay, then this should fix it. Replace the line:
With:
Only the last bit is changed. Without the Code block around it, in your first post the tab character in that line you shared had collapsed to a single space. Should work with this change.
So the entire script becomes:
Code: Select all
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | sed 's/ .*$//g')
Code: Select all
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | cut -f1)
So the entire script becomes:
Code: Select all
#!/bin/bash
# Check if GlidePoint can be found
MATCHES=$(xinput --list | grep GlidePoint | wc -l)
# Check exactly one match was found
if [[ $MATCHES != 1 ]]; then
zenity --error --text="xinput lists no GlidePoint" --title=${0}
exit 1
fi
# Get the ID of the GlidePoint
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | cut -f1)
# Check the match is not zero length
if [[ ${#ID[0]} = 0 ]]; then
zenity --error --text="couldn't find id of GlidePoint" --title=${0}
exit 1
fi
# Disable the GlidePoint
export DISPLAY=:0
xinput set-int-prop $ID "Device Enabled" 8 0
# Check if xinput had an error
if [[ $? != 0 ]]; then
zenity --error --text="xinput failed disabling GlidePoint" --title=${0}
exit 1
fi
Re: Script to turn off laptop touchpad
Thank you Vincent! Works like a charm. I hope this may help other out also. I sure wish I knew how to script like this I'm not the sharpest tool in the shed
Re: Script to turn off laptop touchpad
Ah well, I need to automate something from time to time I keep old scripts around, for later re-use. There are a few good books on shell scripting, but I picked up everything from examples from others & GooglePepi wrote:Thank you Vincent! Works like a charm. I hope this may help other out also. I sure wish I knew how to script like this I'm not the sharpest tool in the shed