#!/bin/bash

SLEEP_TIME=2
GREP_WORD='Mouse'

TOUCHPAD='ON'
while :
do
    (lsusb -v | grep $GREP_WORD) > /dev/null 2>&1
    status=$?
    if [ $status -eq 0 -a $TOUCHPAD = 'ON' ]; then
        TOUCHPAD='OFF'
        synclient TouchpadOff=1 > /dev/null 2>&1 # touchpad off
    elif [ $status -ne 0 -a $TOUCHPAD = 'OFF' ]; then
        TOUCHPAD='ON'
        synclient TouchpadOff=0 > /dev/null 2>&1 # touchpad on 
    fi
    sleep $SLEEP_TIME
done
