You are not logged in.
Pages: 1
Hi all,
I am about to start looking at a script to be executing at a specific time (which shouldn't be too difficult) and then when the time is reach I want a pop up window asking the user a question with a two answer choice (yes or no) and a laps of time for the user to answer.
so basically the script should do that:
x time
pop up window
user to reply yes or no => if yes then do x commands, if no do nothing, if not answer within x time do like yes.
So I will start playing tonight with the time commands, but I do not know how to approach the pop up window? any suggestion?
many thanks for your assistance,
Offline
For the pop-up you could use KDialog.
Here are some examples of use: http://www.wikilearning.com/articulo/sh … ypes/193-5
Offline
For the pop-up you could use KDialog.
Here are some examples of use: http://www.wikilearning.com/articulo/sh … ypes/193-5
There are more dialog utilities if you don't want KDE dependencies. Most notable is zenity which depends only on libnotify and gtk2.
Another possibility is xdialog, which I use for historical reasons only, however.
Or you may even want to use dialog which is a plain text/ncurses implementation.
Last edited by bernarcher (2011-03-21 13:28:11)
To know or not to know ...
... the questions remain forever.
Offline
zenity already has a buildin --timeout option, you can check the return value of zenity to check if the timeout elapsed, which should be 5 then.
Offline
Excellent, thanks for your help...
For info I used Zenity, and to schedule the script at a certain time every day I use cronjob...
Zenity script: taken as example from ubuntu forum (thanks to original creator)
#!/bin/bash
zenity --question --title="Computer Scan" \
--text="A Scan Of Your Computer Is Required! \
Would you like to perform this scan now?"
if [ $? -eq 0 ] ; then
zenity --info --text="Good"
else
zenity --error --text="You pressed NO\!"
fi
And the for the cronjob:
30 22 * * * sh /home/user/script.sh
So every day the script will run at 22:30
Offline
Keep in mind zenity has a different exit code for timeout, but I'm sure you have figured that out by now. Nice work.
Last edited by quigybo (2011-03-22 13:40:56)
Offline
What do you mean? on my script I used "--timeout 10" and if no one press the "yes" then the script will do the "no"
see my script below,
#!/bin/bash
zenity --question --timeout 10 --title="The computer has finish is work" \
--text="The computer has finish is work! \
Should the computer remain on?"
if [[ $? -eq 0 ]] ; then
zenity --info --text=zenity --info --text="Please do not forgot to power down the computer when finish!."
else
pkill ffmpeg
pkill mencoder
sleep 5
procall=`pgrep -u $(whoami) -t tty1` #get all users proceses
procbas=`pgrep -u $(whoami) -t tty1 bash` #get the login bash pid
procxin=`pgrep -u $(whoami) -t tty1 xinit` #get the xinit pid
# nicely terminate all users processes except bash & xinit
for p in $procall; do
if [ "$p" != "$procbas" ] && [ "$p" != "$procxin" ]; then
kill -TERM $p
fi
done
sleep 2
# now KILL the processes that are still alive
for p in $procall; do
if [ "$p" != "$procbas" ] && [ "$p" != "$procxin" ]; then
kill -KILL $p
fi
done
sync
# and finally . . . . we shutdown via hal/dbus
dbus-send --system --print-reply --dest="org.freedesktop.Hal" /org/freedesktop/Hal/devices/computer org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown
fi
Offline
Pages: 1