Script to turn off laptop touchpad

Forum rules
Before you post please read how to get help

Script to turn off laptop touchpad

Postby Pepi on Thu Oct 13, 2011 9:15 am

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
Pepi
Level 1
Level 1
 
Posts: 14
Joined: Wed Nov 18, 2009 7:47 pm

Linux Mint is funded by ads and donations.
 

Re: Script to turn off laptop touchpad

Postby xenopeek on Thu Oct 13, 2011 12:07 pm

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.
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15437
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Script to turn off laptop touchpad

Postby Pepi on Thu Oct 13, 2011 1:21 pm

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,
Pepi
Level 1
Level 1
 
Posts: 14
Joined: Wed Nov 18, 2009 7:47 pm

Re: Script to turn off laptop touchpad

Postby xenopeek on Thu Oct 13, 2011 1:43 pm

Well, I had to take a few guesses from the output you shared :wink: 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).
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15437
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Script to turn off laptop touchpad

Postby Pepi on Thu Oct 13, 2011 2:26 pm

Code: Select all
⎜   ↳ AlpsPS/2 ALPS GlidePoint                   id=13   [slave  pointer  (2)]
13   [slave
Pepi
Level 1
Level 1
 
Posts: 14
Joined: Wed Nov 18, 2009 7:47 pm

Re: Script to turn off laptop touchpad

Postby xenopeek on Thu Oct 13, 2011 4:23 pm

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
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15437
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Re: Script to turn off laptop touchpad

Postby Pepi on Thu Oct 13, 2011 5:17 pm

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 8) I'm not the sharpest tool in the shed :wink:
Pepi
Level 1
Level 1
 
Posts: 14
Joined: Wed Nov 18, 2009 7:47 pm

Re: Script to turn off laptop touchpad

Postby xenopeek on Fri Oct 14, 2011 6:47 am

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 8) I'm not the sharpest tool in the shed :wink:

Ah well, I need to automate something from time to time :wink: 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 8)
User avatar
xenopeek
Level 21
Level 21
 
Posts: 15437
Joined: Wed Jul 06, 2011 3:58 am
Location: The Netherlands

Linux Mint is funded by ads and donations.
 

Return to Scripts & Bash

Who is online

Users browsing this forum: No registered users and 2 guests