lunes, 17 de octubre de 2011

Script para desactivar el touchPad en ubuntu

Hoy navegando por la red he encontrado una utilidad a la que muchos de nosotros le encontraremos bastante utilidad.
Todos los que tengamos portátil sabemos lo fastidioso que llega a ser escribir en ubuntu y que no nos moleste el touchpap (click en lugares que no desesamos, el ratón se "disloca", abre ventanas que estaban en segundo plano), bien pues aquí les traigo un scripts que puede solucionar este problemilla, tan fácil cómo un "Copy/Paste" en un archivo de texto y ejecutarlo, para desactivar/activar el touchpap tan solo hay que pulsar "ALT+T".

#!/bin/bash
#El script MANUAL se encarga de desactivar y activar el touchpad cuando se presiona la combinacion seleccionada
#El script AUTO se encarga de revisar si hay algun raton conectado, y si es asi, desactiva el touchpad
gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_auto-disable true
echo "Generando los scripts"
MANUAL=touchpad-manual
AUTO=touchpad-auto
zenity --question --text="¿Desea activar las notificaciones?\nSe instalara el paquete libnotify-bin\npara lanzar notificaciones a traves de Notify-OSD"
if [ $? = 0 ];then
    gksu echo Instalando
    sudo apt-get install libnotify-bin
    gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_notify true
else
    gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_notify false
fi
echo '#!/bin/bash
gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_auto-disable false
#Si el estado actual es activado, lo desactiva, si no, lo activa
if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_enabled) = true ]; then
    gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_enabled false
    #synclient TouchpadOff=1
    if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_notify) = true ]; then
        notify-send --icon=mouse "Touchpad Deshabilitado"
    fi
else
    gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_enabled true
    #synclient TouchpadOff=0
    if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_notify) = true ]; then
        notify-send --icon=mouse "Touchpad Habilitado"
    fi

fi' | tee $MANUAL

 

echo '#! /bin/bash

# Depende de libnotify-bin

notify=0    # Deshabilita la notificacion en el arranque

# Sincroniza synclient con gconf

#if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_enabled) = true ]; then

#   synclient TouchpadOff=0

#elif [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_enabled) = false ]; then

#   synclient TouchpadOff=1

#fi

while [ 1 ]

do

    if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_auto-disable) = true ]; then

        if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_enabled) = true ] && [ -e /dev/input/by-id/*event-mouse ]; then # Se enchufa un Ratón

            gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_enabled false

            #synclient TouchpadOff=1

            if [ $notify = 1 ]; then

                notify-send --icon=mouse "Touchpad Deshabilitado" "Se ha detectado un Ratón externo"

            fi

 

        elif [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_enabled) = false ] && [ ! -e /dev/input/by-id/*event-mouse ]; then # Se desenchufa un Ratón

            gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_enabled true

            #synclient TouchpadOff=0

            if [ $notify = 1 ]; then

                notify-send --icon=mouse "Touchpad Habilitado" "Se ha desconectado el Ratón externo"

            fi

        fi

    fi

    if [ $(gconftool-2 --get /desktop/gnome/peripherals/touchpad/touchpad_notify) = true ]; then

        notify=1

    fi

    sleep # Periodo de refresco en segundos

done' | tee $AUTO

 

echo "Instalando los script"

gksu cp $MANUAL /usr/bin/

rm $MANUAL

sudo cp $AUTO /usr/bin/

rm $AUTO

cd /usr/bin/

sudo chmod +rx $MANUAL

sudo chmod +rx $AUTO

 

echo "Asociando combinacion de teclas Alt+t"

gconftool-2 -t str --set /apps/metacity/global_keybindings/run_command_8 "<Alt>t"

gconftool-2 -t str --set /apps/metacity/keybinding_commands/command_8 "$MANUAL"

echo "Asociando combinacion de teclas Alt+a para el modo automático"

gconftool-2 -t str --set /apps/metacity/global_keybindings/run_command_7 "<Alt>a"

gconftool-2 -t str --set /apps/metacity/keybinding_commands/command_7 "gconftool-2 --type boolean --set /desktop/gnome/peripherals/touchpad/touchpad_auto-disable true"

 

echo "Creando autoarranque"

cd /usr/share/gnome/autostart/

echo '[Desktop Entry]' | sudo tee $AUTO.desktop

echo 'Type=Application' | sudo tee -a $AUTO.desktop

echo 'Name=AutoDeshabilitar Touchpad' | sudo tee -a $AUTO.desktop

echo "Exec=$AUTO" | sudo tee -a $AUTO.desktop

echo 'Icon=mouse' | sudo tee -a $AUTO.desktop

echo 'Comment=Detecta si exixte un raton, y si es asi, deshabilita el touchpad' | sudo tee -a $AUTO.desktop

echo "Listo"

No hay comentarios:

Publicar un comentario