I am using a bash script to toggle the touchpad on my laptop. I didn't write the script and know almost nothing about bash scripts. I have the script run when the laptop boots because I never want to use the touchpad and want it disabled. The script does the job and then displays a message that the touchpad was toggled off. The message has an OK button that I click to dismiss the message. I would like to alter the script to do something like delay for 5 seconds and then close. I have searched and found how to add the delay for 5 seconds, but would like to know how to dismiss the message window without having to click the OK button. Thanks in advance.

Recommended Answers

All 8 Replies

Can you post the bash script ?

Edit: depending on your system, the libraries for popup dialogs are different. In
KDE, for example, kdialog has an option --passivepopup that does exactly what you want.

I am running PCLOS KDE. Not sure how to wrap the script code so here it is:

#! /bin/bash

PATH=${PATH}:/usr/sbin:/sbin

T=0
M=0

lsusb -v |grep "Mouse" &> /dev/null

if [ "$?" -ne "$M" ]; then


    export MAIN_DIALOG='
        <window title="TouchPad Toggle" icon-name="gtk-dialog-info">
        <frame WARNING>
        <vbox>
        <hbox>
        <pixmap>
            <input file stock="gtk-dialog-warning"></input>
        </pixmap>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>"You are attempting to run Touchpad Toggle 
without a USB Mouse being attached or detected."</label>
        </text>
        </hbox>
        <hbox>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <text wrap="true" width-chars="35">
        <label>"Unless you have an alternate poiniting device (e.g., 
keyboard based mouse stick), please plug in a USB Mouse. Otherwise, you may not 
have access to a pointing device. Re-run Touchpad Toggle to toggle the state of 
your touchpad."</label>
        </text>
        </hbox>
        <hbox>
        <text>
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <button ok></button>
        </hbox>
        </vbox>
        </frame>
        </window>
        '

    gtkdialog --program=MAIN_DIALOG
    fi
fi

synclient -l |grep "TouchpadOff             = 0" &> /dev/null

if [ "$?" -eq "$T" ]; then
#   then
        synclient TouchpadOff=1

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" 
icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" wrap="true" width-chars="35">
                <label>"Your Touchpad has been turned 
<b>OFF</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your 
touchpad on again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            </window>
            '

        gtkdialog --program=MAIN_DIALOG
    fi

#       exit 0
    else
        synclient TouchpadOff=0

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" 
icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" width-chars="35">
                <label>"Your Touchpad has been turned 
<b>ON</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your 
touchpad off again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            </window>
        '

        gtkdialog --program=MAIN_DIALOG
    fi
fi
#fi
exit 0

Thanks. I will give it a try. Since I know nothing about writing scripts I will be sure and make a copy of the script before I start. The links seem very complicated to me. I will try your example and try to figure out where to put it.

I put your timer code into the script and now nothing is displayed. I was hoping to display the OK window for a few seconds (say 5 seconds) and then close the window. Here is where I put it in:

#! /bin/bash

PATH=${PATH}:/usr/sbin:/sbin

T=0
M=0

lsusb -v |grep "Mouse" &> /dev/null

if [ "$?" -ne "$M" ]; then
    if [ "$1" != "--no-gui" ]; then

    export MAIN_DIALOG='
        <window title="TouchPad Toggle" icon-name="gtk-dialog-info">
        <frame WARNING>
        <vbox>
        <hbox>
        <pixmap>
            <input file stock="gtk-dialog-warning"></input>
        </pixmap>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>"You are attempting to run Touchpad Toggle without a USB Mouse being attached or detected."</label>
        </text>
        </hbox>
        <hbox>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <text wrap="true" width-chars="35">
        <label>"Unless you have an alternate poiniting device (e.g., keyboard based mouse stick), please plug in a USB Mouse. Otherwise, you may not have access to a pointing device. Re-run Touchpad Toggle to toggle the state of your touchpad."</label>
        </text>
        </hbox>
        <hbox>
        <text>
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <button ok></button>
        </hbox>
        </vbox>
        </frame>
        </window>
        '

    gtkdialog --program=MAIN_DIALOG
    fi
fi

synclient -l |grep "TouchpadOff             = 0" &> /dev/null

if [ "$?" -eq "$T" ]; then
#   then
        synclient TouchpadOff=1

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" wrap="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>OFF</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad on again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame> 

here <timer interval="5">
here <action>EXIT:ok</action>
here </timer>/window>
'

        gtkdialog --program=MAIN_DIALOG
    fi

#       exit 0
    else
        synclient TouchpadOff=0

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>ON</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad off again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            </window>
        '

        gtkdialog --program=MAIN_DIALOG
    fi
fi
#fi
exit 0

Now the OK window doesn't show.

The closing </window> tag is incorrect in your example above. Can you post the code with the timer included ? Did you try to put the timer before the </vbox> ?

Below is the script code as I have it saved in my system.

#! /bin/bash

PATH=${PATH}:/usr/sbin:/sbin

T=0
M=0

lsusb -v |grep "Mouse" &> /dev/null

if [ "$?" -ne "$M" ]; then
    if [ "$1" != "--no-gui" ]; then

    export MAIN_DIALOG='
        <window title="TouchPad Toggle" icon-name="gtk-dialog-info">
        <frame WARNING>
        <vbox>
        <hbox>
        <pixmap>
            <input file stock="gtk-dialog-warning"></input>
        </pixmap>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>"You are attempting to run Touchpad Toggle without a USB Mouse being attached or detected."</label>
        </text>
        </hbox>
        <hbox>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <text wrap="true" width-chars="35">
        <label>"Unless you have an alternate poiniting device (e.g., keyboard based mouse stick), please plug in a USB Mouse. Otherwise, you may not have access to a pointing device. Re-run Touchpad Toggle to toggle the state of your touchpad."</label>
        </text>
        </hbox>
        <hbox>
        <text>
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <button ok></button>
        </hbox>
        </vbox>
        </frame>
        </window>
        '

    gtkdialog --program=MAIN_DIALOG
    fi
fi

synclient -l |grep "TouchpadOff             = 0" &> /dev/null

if [ "$?" -eq "$T" ]; then
#   then
        synclient TouchpadOff=1

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" wrap="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>OFF</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad on again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            <timer interval="5">
            <action>EXIT:ok</action>
            </timer>/window>

            '

        gtkdialog --program=MAIN_DIALOG
    fi

#       exit 0
    else
        synclient TouchpadOff=0

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>ON</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad off again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            </window>
        '

        gtkdialog --program=MAIN_DIALOG
    fi
fi
#fi
exit 0

Try this version perhaps ...

#! /bin/bash

PATH=${PATH}:/usr/sbin:/sbin

T=0
M=0

lsusb -v |grep "Mouse" &> /dev/null

if [ "$?" -ne "$M" ]; then
    if [ "$1" != "--no-gui" ]; then

    export MAIN_DIALOG='
        <window title="TouchPad Toggle" icon-name="gtk-dialog-info">
        <frame WARNING>
        <vbox>
        <hbox>
        <pixmap>
            <input file stock="gtk-dialog-warning"></input>
        </pixmap>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>"You are attempting to run Touchpad Toggle without a USB Mouse being attached or detected."</label>
        </text>
        </hbox>
        <hbox>
        <text use-markup="true" wrap="true" width-chars="35">
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <text wrap="true" width-chars="35">
        <label>"Unless you have an alternate poiniting device (e.g., keyboard based mouse stick), please plug in a USB Mouse. Otherwise, you may not have access to a pointing device. Re-run Touchpad Toggle to toggle the state of your touchpad."</label>
        </text>
        </hbox>
        <hbox>
        <text>
            <label>" "</label>
        </text>
        </hbox>
        <hbox>
        <button ok></button>
        </hbox>
        </vbox>
        </frame>
        </window>
        '

    gtkdialog --program=MAIN_DIALOG
    fi
fi

synclient -l |grep "TouchpadOff             = 0" &> /dev/null

if [ "$?" -eq "$T" ]; then
#   then
        synclient TouchpadOff=1

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" wrap="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>OFF</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad on again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            <timer interval="5">
                <action>EXIT:ok</action>
            </timer>
            </vbox>
            </frame>
            </window>
            '

        gtkdialog --program=MAIN_DIALOG
    fi

#       exit 0
    else
        synclient TouchpadOff=0

    if [ "$1" != "--no-gui" ]; then
        export MAIN_DIALOG='
            <window title="Touchpad Toggle" icon-name="gtk-dialog-info">
            <frame>
            <vbox>
            <hbox>
            <pixmap>
                <input file stock="gtk-info"></input>
            </pixmap>
            <text use-markup="true" width-chars="35">
                <label>"Your Touchpad has been turned <b>ON</b>."</label>
            </text>
            </hbox>
            <hbox>
            <text>
                <label>" "</label>
            </text>
            </hbox>
            <hbox>
            <text use-markup="true">
                <label>"<i>Re-run this program to turn your touchpad off again.</i>"</label>
            </text>
            </hbox>
            <hbox>
                <button ok></button>
            </hbox>
            </vbox>
            </frame>
            </window>
        '

        gtkdialog --program=MAIN_DIALOG
    fi
fi
#fi
exit 0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.