Powered By

Powered by Blogger

Jumat, 03 Desember 2010

YAD: Zenity On Steroids [Display Graphical Dialogs From Shell Scripts]

Those of you who like writing bash scripts and use Zenity for a GUI should give YAD a try. YAD (Yet Another Dialog) is a fork of Zenity with many improvements, such as custom buttons, additional dialogs, pop-up menu in notification icon and more. I've been using it for Y PPA Manager so if you want to see it in action, give Y PPA Manager a try.

Unfortunately even though Zenity is constantly updated, these updates only bring language updates and fixes. Here is where YAD shines: basically most of the stuff you ever wanted to do in Zenity is available in YAD: you can have as many buttons as you want, each with the text you want, a really nice icons dialog (which I've used as the main Y PPA Manager UI) and many more. Here's an example of a YAD dialog you could never get using Zenity:


If you want to convert a script from using Zenity to YAD, there are a few things you'll have to change, but it's worth it. YAD doesn't have all the useless dialogs such as --error, --info, --notification, --question or --warning - instead, it has a --form dialog to which you can add whatever message, buttons and icons you want. For help on using YAD (it's quite easy!), see the examples sections at it's Wiki or have a look at Y PPA Manager code. Here is the code (thanks to ananasik) used to generate the dialog in the above screenshot:
yad --title="Desktop entry editor" --text="Simple desktop entry editor" --form --field="Type:CB" --field="Name" --field="Generic name" --field="Comment" --field="Command:FL" --field="Icon" --field="In terminal:CHK" --field="Startup notify:CHK" "Application" "Name" "Generic name" "This is the comment" "/usr/bin/yad" "yad" FALSE TRUE --button="WebUpd8:2" --button="gtk-ok:0" --button="gtk-cancel:1"

Install YAD in Ubuntu

If you're using Ubuntu, you can install the latest YAD from the Y PPA Manager WebUpd8 PPA (available for Ubuntu Karmic, Lucid, Maverick and Natty):
sudo add-apt-repository ppa:webupd8team/y-ppa-manager
sudo apt-get update
sudo apt-get install yad

To see all the available options, type:
yad --help-all

For those of you who don't use Ubuntu, download YAD source @ Google Code.

If you find a bug or have a feature request, don't hesitate in reporting it on YAD's Google Code page - it's developer is really nice and he always tries to help.

Tidak ada komentar:

Posting Komentar