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.

Dani AI

Generated

The dialog XML you posted stops showing because gtkdialog expects a well‑formed, containerized description — a stray or mismatched tag will make the whole GUI definition fail. was right to ask about placement: every widget (including <timer>) must sit inside a container such as a <vbox> or <hbox>, and the dialog language is strict about matching open/close tags. (xpt.sourceforge.net)

Quick checklist to fix the script (in order of what actually breaks things):

  • Remove any stray characters after the </timer> close (your /window> at the end is exactly the sort of syntax error that prevents display).
  • Put the <timer> element as a child inside the same box that contains your button (i.e. before the </vbox>), so it’s parsed as a widget rather than dangling outside the window. Examples in the gtkdialog docs show timers used this way; many examples also use a milliseconds="true" attribute and an interval of 5000 to mean five seconds. (xpt.sourceforge.net)

If it still won’t show, test the dialog definition outside the script so you can see parse errors:

printf '%s\n' "$MAIN_DIALOG" > /tmp/dialog.gtkd
gtkdialog --file=/tmp/dialog.gtkd 2>/tmp/gtkdialog.err || cat /tmp/gtkdialog.err

Running gtkdialog --file=... or gtkdialog --program=MAIN_DIALOG 2>/tmp/err isolates parsing/runtime errors and prevents service/boot scheduling from hiding problems. The examples/docs show both approaches. (xpt.sourceforge.net)

If you only want a short, non‑blocking notification (no OK button at all) consider notify-send -t 5000 "Touchpad toggled off", which uses the desktop notification system (timeout in milliseconds). That avoids dialog XML entirely and integrates with KDE’s notification daemon. (manpages.debian.org)

Notes: keep the outer shell quote style consistent (export MAIN_DIALOG='...') and avoid unescaped single quotes inside that block. Also remember that a GUI tool run “at boot” must have an X/desktop session available (DISPLAY/DBUS session) to actually appear.

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.