#!/bin/bash

SLEEP_TIME=2
GREP_WORD='Mouse'
# NOTIFY SEND PARAMETER
NOTIFY_TITLE='Touchpad'
NOTIFY_TIME=5000

TOUCHPAD='ON'
while :
do
    notify=''
    (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
        notify='Disabled Touchpad.'
    elif [ $status -ne 0 -a $TOUCHPAD = 'OFF' ]; then
        TOUCHPAD='ON'
        synclient TouchpadOff=0 > /dev/null 2>&1 # touchpad on 
        notify='Enabled Touchpad.'
    fi
    if [ "$notify" != "" -a "$DISPLAY" != "" ]; then
        notify-send -t $NOTIFY_TIME "$NOTIFY_TITLE" "$notify"
    fi
    sleep $SLEEP_TIME
done
