MLUG Bash Scripting Workshop 25/04/08 | ||
---|---|---|
Prev | Index | Next |
You might be thinking that Bash scripts are only good for use on a console or for system operations where there will be no console interface, but that is not necessarily the case.
There are applications available that allow you to create GUI interface for scripts.
The image below shows a kdialog pop-up window that is displayed when I run a script named audcap from an icon on my desktop. I use audcap to capture audio from my soundcard. If I want to grab some music I'm streaming or dialog from a movie, I just hit the icon and this window pops up and asks me to enter how many minutes to save.
The line that creates this pop-up looks like this:
# Use a KDE dialog popup to get the duration of recording # $duration is assigned the number entered in the kdialog box duration=`kdialog --title "audcap" --inputbox "Enter The number of minutes to save audio:"`
The next image is from a rather dated script from back in my dial-up days. We had two workstations. My box was configured as a gateway and had a a modem for dialup connections and my daughter was connected to me with a NIC and crossover cable. If she wanted to get on the internet she had to hope I was logged in and connected or else turn on my box, log into her account and then log onto our ISP.
I made up a script that used gxmessage to display on my daughter's desktop the necessary info for making a dialup connection remotely. All she had to do was hit an icon on her desktop and the script was run on my box with passwordless ssh in the middle.
Here is are the lines from from gx-logon that create this pop-up. Note that that the variable $XMESSAGE is the variable for the pathe to gx-message, /usr/local/bin/gxmessage.
echo -e "You are already connected.\nDo you want to disconnect now?" | $XMESSAGE -nearmouse \ -title $TITLE \ -geometry $SMALLSIZE \ -file - \ -buttons Disconnect:1,Continue:2
There are some people who'd argue that the next image has nothing to do with GUI interface. Maybe it's halfway between console and GUI.... a missing link perhaps.
This script is called stream-tv. It can be run by anyone with a user account on our server via ssh session. The script will lock onto (tune into) a DVB-T broadcast and stream it on our network. Since this is on the server, dialog and ncurses do the work in an ssh session on a terminal.
Here are the relevant lines from the script:
dialog --title "Stream-TV" --radiolist "Select a station:" 12 30 6 \ 0 "SBS" 'on_off $SBC_IRQ 0' \ 1 "ABC" 'on_off $SBC_IRQ 1' \ 2 "ABC2" 'on_off $SBC_IRQ 2' \ 7 "Seven Digital" 'on_off $SBC_IRQ 7' \ 9 "Nine Digital" 'on_off $SBC_IRQ 9' \ 10 "Ten Digital" "on_off $SBC_IRQ 10" 2> $TEMP