This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Scripting 101

Class log Class 12

hemanth hm's picture
Sun, 2010-10-24 18:20

* hemanth has changed the topic to: Interactive Scripts in BASH
* lakshmi (51628a42@gateway/web/freenode/ip.81.98.138.66) has joined #p2pu-webcraft/scripting-101
<hemanth> As per our list,  Interactive Scripts is the last topic
<hemanth> but its last for BASH
<hemanth> but just the start for others, as we need to do lot of OOP
<hemanth> for py,rb and pl
<hemanth> so today is indeed a very very short session, on making interactive scripts i.e with GUI support
<hemanth> in BASH so far, we have see lot of things,  but not ventured to make something that runs with GUI
<hemanth> GUI => "Graphical User Interface, a system whereby the user interacts with a computer via a picture-based, graphic medium."
<hemanth> so, how could we make bash scripts to have clean and easy GUI ?
<hemanth> BASH by itself does not give support for this....
<hemanth> but we have many helper programs which makes things better for us
<hemanth> but at the end of the day, bash was not made for funky GUI
<hemanth> but it's for strong CLI magic
<hemanth> listing those helpers :
<hemanth> we have dialog, kdialog, zenity, easybashgui, Kommander
<hemanth> and few others, they are coupled to KDE and GNOME
<hemanth> but as of i have tested, zenity is pretty easy and good
<hemanth> except for the limitations that it can't have complex window frames
<hemanth> say like multiple inputs and outputs
* lakshmi has quit (Ping timeout: 265 seconds)
<hemanth> http://live.gnome.org/Zenity
<hemanth> one can fetch the source there
<hemanth> or do sudo apt-get install zenity
<hemanth> 10.04+ if ubuntu has zenity installed by default
<hemanth> port install zenity SourRust  works for mac?
* lakshmi (51628a42@gateway/web/freenode/ip.81.98.138.66) has joined #p2pu-webcraft/scripting-101
<SourRust> nope but im pretty sure i can get it installed
<hemanth> okies :) once you do, do put a comment under the chat log, so it would be useful for others
<hemanth> tar.gz source if could be installed as =>  ./configure && make && make install
<hemanth> wget http://caesar.acc.umu.se/pub/GNOME/sources/zenity/2.20/zenity-2.20.1.tar.gz && tar xzf zenity-2.20.1.tar.gz  && cd zenity-2.20.1 && ./configure && make && sudo make install
<hemanth> can be done :) even for mac i blv
<hemanth> lakshmi, you got zenity ?
<hemanth> take few mins, get it up now, cos class wont be fun without installing it
<lakshmi> hi my laptop with ubuntu has crashed
<hemanth> bug report please
<lakshmi> I will just listen today , I will try sometime later
<hemanth> okies
<hemanth> zenity  is a program that will display GTK+ dialogs, and return (either  in the return code, or on standard output) the users input.
<hemanth> for example zenity  --title="Select a file" --file-selection
<hemanth> will give a window, with which you can browser through the system and select the file
<hemanth> the selected files path will be returned
<hemanth> so in the bash script on could say
<hemanth> selected_file=$(zenity  --title="Select a file" --file-selection)
<lakshmi> ok
<hemanth> then do what ever with the file, so instead of asking the user to give the path to the file, or rather asking him to pass it as a param to the script
<hemanth> we could make a --file-selection UI
<hemanth> zenity --calendar --title="My Cal"
<hemanth> will give a calendar!
<hemanth> Sunday 24 October 2010
<lakshmi> oh thats good
<hemanth> would the return value, if we select todays date
<hemanth> --day=23 --month=10 --year=2010
<hemanth> if one uses that param, the cal's default highlighted date will be the date mentioned
<hemanth> zenity --notification --window-icon="info" --text="There are system updates necessary!"
<hemanth> will give a window-icon
<hemanth> we can have list
<hemanth> zenity --list  --column="c1" --column="c2" --column="c3" this that them
<hemanth> will make three columns
<hemanth> with what ever data we give
<hemanth>  zenity --error --text="Fatal Error!"
<hemanth> will say an error window
<hemanth>  zenity --info --text="Installing this..."
<hemanth> will just give an info box
<lakshmi> ok
<hemanth>  zenity --question  --text="IS this not fun?"
<hemanth> a question window
<hemanth> that is there will be an appropriate window icon
<hemanth> zenity --warning for warnings
<hemanth> zenity --progress --title="Please wait" --text="Scanning mail logs..."  --percentage=0
<hemanth> that will give a progress bar!
<lakshmi> how dowe update the percentage
<lakshmi> ?
<hemanth> find $HOME -name '*.pdf' | zenity --progress --pulsate
<hemanth> that will pulsate
<hemanth> --percentage=0 means it starts with zero
<hemanth> so when you have cmd1 |  zenity --progress ...
<hemanth> it will run as the cmd1 runs
<lakshmi> ok
<lakshmi> and the progress bar will update accordingly?
<hemanth> yup :)
<hemanth> zenity --progress --title="Please wait" --text="Scanning mail logs..."  --percentage=0 will just be a progress bar which will never update
<hemanth> as it does not know how much to update
<hemanth> [ "$?" = -1 ] && echo progress was canceled
<hemanth> we can use to get password entires like
<hemanth> if zenity --entry \
<hemanth>         --title="Add an Entry" \
<hemanth>         --text="Enter your _password:" \
<hemanth>         --entry-text "password" \
<hemanth>         --hide-text
<hemanth>           then echo $?
<hemanth>           else echo "No password entered"
<hemanth>         fi
<hemanth>  --hide-text will mask the password for us :)
<hemanth> http://www.h3manth.com/content/one-line-search-wiki-linux-gui
* lakshmi_ (51628a42@gateway/web/freenode/ip.81.98.138.66) has joined #p2pu-webcraft/scripting-101
<hemanth> i had used zenity to make a one line search tool for wikipedia
<hemanth> so, its all fun with zenity
* lakshmi has quit (Ping timeout: 265 seconds)
<hemanth> in the same way dialog - display dialog boxes from shell scripts
<hemanth> kdialog is for KDE env
<hemanth> we also have http://kde-apps.org/content/show.php?content=12865
<hemanth> i.e Kommander
<hemanth> http://sites.google.com/site/easybashgui/ i personally didn't like it much
<hemanth> all this are pretty much similar to zenity
<hemanth> will few other window options
<lakshmi_> ok
<hemanth> So, just download install them and try using them, there is not out of the box, mind blowing technical stuff needed here, unless one is playing to contribute it to
<hemanth> but its fun
<lakshmi_> hmmm
<hemanth> one could try to make simple app, like twitter stats update
<hemanth> but need to crack head on oauth
<hemanth> as basic auth does not work with twitter any more
<hemanth> i wont confine or stop you from making a beautiful app using any of these helpers GUI programs
<hemanth> so, do try it and push it to the repo
<hemanth> any doubts so far?
<SourRust> nope
<lakshmi_> ok
<lakshmi_> no
<hemanth> kool, so this officially brings an end to BASH, but just a start for py,rb and pl
<hemanth> there are still more to come
<lakshmi_> ok
<lakshmi_> :)
<hemanth> but infinite possibility  drive with  BASH must make anyone crazy
<hemanth> learn never stops
<hemanth> as Charlie Chaplin said, we all are learners, life is to short to be an expert in anything :)
<hemanth> So, with this if all is fine, i will end the class here, 10 mins early today
<hemanth> and from next class we will have OOP!
* hemanth claps :)
<SourRust> :)
<lakshmi_> :)
<hemanth> So, cya all
<hemanth> happy hacking till then
<lakshmi_> see you next week
<SourRust> yup cya
<hemanth> :)