Page 1 of 1
Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 9:15 am
by Pepi
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
Re: Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 12:07 pm
by xenopeek
Create a file as follows (you can just use gedit / Text Editor from the menu):
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
For example, call it "Disable-GlidePoint" or something. Then right-click it, properties, permissions, and set to allow it for executing.
Re: Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 1:21 pm
by Pepi
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,
Re: Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 1:43 pm
by xenopeek
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:
Code: Select all
xinput --list | grep GlidePoint >> ~/Desktop/output
xinput --list | grep GlidePoint | sed 's/^.*id=//g' | sed 's/ .*$//g' >> ~/Desktop/output
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).
Re: Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 2:26 pm
by Pepi
Code: Select all
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=13 [slave pointer (2)]
13 [slave
Re: Script to turn off laptop touchpad
Posted: Thu Oct 13, 2011 4:23 pm
by xenopeek
Okay, then this should fix it. Replace the line:
Code: Select all
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | sed 's/ .*$//g')
With:
Code: Select all
ID=$(xinput --list | grep GlidePoint | sed 's/^.*id=//g' | cut -f1)
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
#!/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
Posted: Thu Oct 13, 2011 5:17 pm
by Pepi
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
Posted: Fri Oct 14, 2011 6:47 am
by xenopeek
Pepi 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
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 & Google