20
Search Select Language Powered by Translate Advertise Linux Services About Archives Contact Us Copyright Policy Home Linux Distro’s Interview Questions Shell Scripting Free Linux eBooks Linux Commands Did You Know? We are pleased to announce our new TecMint Q/A section to submit your Linux questions Zenity – Creates Graphical (GTK+) Dialog Boxes in Command-line and Shell Scripts By Avishek Kumar Under: Bash Shell, Open Source Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators GNU Linux, the operating system built on very powerful Linux is famous for its command Line operations. With the invent of Linux in day-to-day and Desktop computing, nix remains no more biased towards command-Line, it is equally Graphical and developing Graphical application Stay updated. Follow us on facebook. Linux Inside 36,812 people like Linux Inside. Facebook social plugin Like Like Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-... 1 of 20 Saturday 12 July 2014 05:09 PM

Shell Dialog Box

Embed Size (px)

DESCRIPTION

Shell Programming

Citation preview

Page 1: Shell Dialog Box

Search

Select Language Powered by Translate

AdvertiseLinux ServicesAboutArchivesContact UsCopyright Policy

HomeLinux Distro’sInterview QuestionsShell ScriptingFree Linux eBooksLinux Commands

Did You Know?

We are pleased to announce our new TecMint Q/Asection to submit your Linux questions

Zenity – Creates Graphical (GTK+) Dialog Boxesin Command-line and Shell Scripts

By Avishek Kumar Under: Bash Shell, Open Source

Download Your Free eBooks NOW - 10 Free Linux eBooks for Administrators

GNU Linux, the operating system built on very powerful Linux is famous for its command Line operations. With the invent of Linux inday-to-day and Desktop computing, nix remains no more biased towardscommand-Line, it is equally Graphical and developing Graphical application

Stay updated. Follow us onfacebook.

Linux Inside

36,812 people like Linux Inside.

Facebook social plugin

Like

Like

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

1 of 20 Saturday 12 July 2014 05:09 PM

Page 2: Shell Dialog Box

remains no more a difficult task.

Zenity Display Graphical Boxes

Here in this article we will be discussing creation and execution of simpleGraphical Dialog box using GTK+ application called “

What is Zenity?

Zenity is an open source and a cross-platform application which displays Dialog Boxes in command-line and using shell scripts. It allows to ask andpresent information to/from shell in Graphical Boxes. The application lets youcreate Graphical dialog boxes in command-line and makes the interactionbetween user and shell very easy.

There are other alternatives, but nothing compares to the simplicity of specially when you don’t need complex programming. Zenity, a tool you musthave your hands on.

Zenity Features

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

2 of 20 Saturday 12 July 2014 05:09 PM

Page 3: Shell Dialog Box

FOSS Software1.Cross Platform Application2.Allow GTK+ Dialog Box Execution3.Command Line Tool4.Support in Shell Scripting5.

Usefulness

Easy GUI Creation1.Less features than other complex Tools2.Enables shell scripts to interact with a GUI users3.Simple dialog creation is possible for graphical user interaction4.

Since Zenity is available for all known major platforms, and based on GTK+library, Zenity program can be ported to/from another platform.

Installation of Zenity in Linux

Zentity is by default installed or available in repository of most of the StandardLinux distribution of today. You can check if is installed onto your machine or notby executing following commands.

ravisaive@tecmint:~$ zenity --version

3.8.0

ravisaive@tecmint:~$ whereis zenity

zenity: /usr/bin/zenity /usr/bin/X11/zenity /usr/share/zenity /usr/share/man/man1/zenity.1.gz

If it’s not installed, you can install it using command as shown below.

ravisaive@tecmint:~$ sudo apt-get install zenity [on

root@tecmint:~# yum install zenity [on

Moreover you can also build it from the source files, download the latest source package (i.e. current version 3.8

http://ftp.gnome.org/pub/gnome/sources/zenity/1.

Zenity Basic Dialog Boxes

Some of the basic Dialogs of Zenity, which can be invoked directly from thecommand-line.

1. How about a quick calendar dialog?

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

3 of 20 Saturday 12 July 2014 05:09 PM

Page 4: Shell Dialog Box

root@tecmint:~# zenity --calendar

Calendar Dialog

2. An error Dialog Box

root@tecmint:~# zenity --error

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

4 of 20 Saturday 12 July 2014 05:09 PM

Page 5: Shell Dialog Box

Error Dialog

3. A General text Entry Dialog Box

root@tecmint:~# zenity --entry

Entry Dialog

4. An Information Dialog

root@tecmint:~# zenity --info

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

5 of 20 Saturday 12 July 2014 05:09 PM

Page 6: Shell Dialog Box

Info Dialog

5. A question Dialog box

root@tecmint:~# zenity --question

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

6 of 20 Saturday 12 July 2014 05:09 PM

Page 7: Shell Dialog Box

Question Box

6. A progress Bar

root@tecmint:~# zenity --progress

Progress Bar

7. Scale Dialog

root@tecmint:~# zenity --scale

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

7 of 20 Saturday 12 July 2014 05:09 PM

Page 8: Shell Dialog Box

Scale Box

8. A Password Dialog

root@tecmint:~# zenity --password

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

8 of 20 Saturday 12 July 2014 05:09 PM

Page 9: Shell Dialog Box

Password Box

9. A Form Dialog box

root@tecmint:~# zenity --forms

Forms

10. An about Dialog

root@tecmint:~# zenity --about Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

9 of 20 Saturday 12 July 2014 05:09 PM

Page 10: Shell Dialog Box

About Zenity

Create Shell Script Dialog

Now we would be discussing Zenity Dialog creation using simple shell scriptshere. Although we can create single Dialog by executing Zenity commandsdirectly from the shell (as we did above) but then we can’t link two Dialog boxesin order to obtain some meaningful result.

How about an interactive dialog box which takes input from you, and shows theresult.

#!/bin/bash first=$(zenity --title="Your's First Name" --text "What is your first name?" --entry) zenity --info --title="Welcome" --text="Mr./Ms. $first" last=$(zenity --title="Your's Last Name" --text "$first what is your last name?" --entry) zenity --info --title="Nice Meeting You" --text="Mr./Ms. $first $last"

Save it to ‘anything.sh‘ (conventionally) and do not forget to make it executable.Set 755 permission on anything.sh file and run the script.

root@tecmint:~# chmod 755 anything.sh root@tecmint:~# sh anything.sh

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

10 of 20 Saturday 12 July 2014 05:09 PM

Page 11: Shell Dialog Box

Enter Your First Name

Welcome Dialog

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

11 of 20 Saturday 12 July 2014 05:09 PM

Page 12: Shell Dialog Box

Enter Your Last Name

Welcome Message

About Script Description

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

12 of 20 Saturday 12 July 2014 05:09 PM

Page 13: Shell Dialog Box

Bio Latest Posts

The conventional shebang aka hashbang

#!/bin/bash

In the below line ‘first’ is a variable and the value of variable is Generated at runtime.

‘–entry‘ means zenity is asked to generate an text Entry box.1.‘– title=‘ defines the title of generated text box.2.‘—text=‘ defines the text that is available on text Entry box.3.

first=$(zenity --title="Your's First Name" --text "What is your first name?" --entry)

This line of the below script file is for generation of Information (–info) Dialogbox, with title “Welcome” and Text “Mr./Ms.first”

zenity --info --title="Welcome" --text="Mr./Ms. $first"

This Line of the script is Similar to line number two of the script except here anew variable ‘last’ is defined.

last=$(zenity --title="Your's Last Name" --text "$first what is your last name?" --entry)

This last line of the script is again similar to the third line of the script and itgenerates information Dialog box which contains both the variables ‘$first’ and‘$last’.

zenity --info --title="Nice Meeting You" --text="Mr./Ms. $first $last"

For more information on how to create custom dialog boxes using shell script,visit at following reference page Zenity.

https://help.gnome.org/users/zenity/stable/1.

In the next article we would be integrating user interaction. Till then stay tuned and connected to give your valuable feedback in comment section.

Avishek Kumar

I am a major in computer science, love to research nix. I love to

write codes and scripts, review distros, experiment Foss

Technologies, write technical articles, Hack, of course Ethically. I

am working as System Administrator (nix) for a NGO.

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

13 of 20 Saturday 12 July 2014 05:09 PM

Page 14: Shell Dialog Box

Linux Services & Free WordPressSetup

Our post is simply ‘DIY’ aka ‘Do It Yourself, still you may find difficulties andwant us to help you out. We offer wide range of Linux and Web HostingSolutions at fair minimum rates. Please submit your orders by Clicking Here.

TweetTweet

11

63

LikeLike

16

1 comment

« Previous Post

Adminer – A Advanced Web Based Databases Administration Tool for Linux

Next Post »

I-Nex – An Advanced Tool to Collect System/Hardware Information in Linux

Related Post(s):

How to Install Asterisk 11 in RHEL/CentOS/Fedora and Ubuntu/Debian/Linux Mint

1.

Nikto – A Web Application Vulnerability and CGI Scanner for Web Servers2.Create Your Own Instant Messaging/Chat Server Using “Openfire” in Linux3.

11

ShareShare Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

14 of 20 Saturday 12 July 2014 05:09 PM

Page 15: Shell Dialog Box

PHPlist – Open Source Email Newsletter Manager (Mass Mailing)Application for Linux

4.

Install RainLoop Webmail (A Web Based Email Client) using ‘Nginx andApache’ in Arch Linux

5.

Ethernet Channel Bonding aka NIC Teaming on Linux Systems6.

One Response

Mahesh says:April 8, 2014 at 10:09 am

hey! I happen to find this blog today (apr 08, 2014) because of Tarunika’srsync article (http://www.tecmint.com/rsync-local-remote-file-synchronization-commands/). So, i continued browsing through your siteand found this article.

Just a few months back I wrote and published a simple show clock (date,time) shell script that uses Zenity. Please find it here:http://thatmaheshrs.wordpress.com/2014/02/09/show-date-and-time-in-xubuntu-as-well-as-other-linux-distros/

Please post your constructive comments, if any, onto my blog.

Reply

1.

Leave a Reply

Name (Required)

Mail (will not be published) (Required)

Website

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

15 of 20 Saturday 12 July 2014 05:09 PM

Page 16: Shell Dialog Box

Submit Comment

Twitter 1614 Twitter

Facebook 36808 Facebook

Google+ 5137 Google+

RSS 3536 Subscribers

Become A TecMint Subscriber to receive latest Updates.

Enter Your Email Address :) Signup!

PopularLatestCommentsTags

How to Add Linux Host to Nagios Monitoring Server Using NRPE Plugin 190Comments

Wine 1.6.2 Stable Released – Install in RHEL, CentOS and FedoraComments

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

16 of 20 Saturday 12 July 2014 05:09 PM

Page 17: Shell Dialog Box

Nagios 4.0.1 Released – Install on RHEL/CentOS 6.x/5.x and Fedora19/18/17 158 Comments

CentOS 6.4 Step by Step Installation Guide with Screenshots 155 Comments

Install Apache 2.2.15, MySQL 5.5.34 & PHP 5.5.4 on RHEL/CentOS 6.4/5.9& Fedora 19-12 151 Comments

Google Chrome 35 Released – Install on RHEL/CentOS 6 and Fedora 20-15127 Comments

:: Advertise ::

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

17 of 20 Saturday 12 July 2014 05:09 PM

Page 18: Shell Dialog Box

:: Download Free Linux eBooks ::

Complete Linux Command Line Cheat SheetThe GNU/Linux Advanced Administration GuideSecuring & Optimizing Linux ServersLinux Patch Management: Keeping Linux Up To DateIntroduction to Linux – A Hands on GuideUnderstanding the Linux® Virtual Memory ManagerLinux Bible – Packed with Updates and ExercisesA Newbie’s Getting Started Guide to LinuxLinux from Scratch – Create Your Own Linux OSLinux Shell Scripting Cookbook, Second EditionSecuring & Optimizing Linux: The Hacking Solution

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

18 of 20 Saturday 12 July 2014 05:09 PM

Page 19: Shell Dialog Box

Know More

User Mode Linux – Understanding and Administration

:: Follow Us ::

TecMint.comgoogle.com/+Tecmint

Tecmint: Linux Howtos, Tutorials & Guides

+ 5,144

Follow +1

:: About ::

TecMint.com is a website that publishes practical and useful out-of-the-boxarticles for aspirant like you and me. We seek to present exceptional, remarkabletips, tutorials, and resources that the modern web professional will appreciate.

:: Our Services ::

We offer wide range of Linux Web Hosting and Management Servicesincludes Linux hosting, WordPress hosting, Joomla Hosting, CMS hosting,Website migration and Custom solutions, making us a one-stop destination for allyour possible hosting needs at fair minimum rates.

:: Advertise ::

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

19 of 20 Saturday 12 July 2014 05:09 PM

Page 20: Shell Dialog Box

Submit Order

Advertise Now

TecMint.com is visited by tens of thousands of Linux users and hasa excellent reputation in the search engine ranking. Most of thetraffic comes from Google organic search (80%). Spread yourmessages or products to an engaged readers by advertising with us.

This work is licensed under a (cc) BY-NC | TecMint uses cookies.By using our services, you comply to use of our cookies. More info:Privacy Policy.© 2012-2014 All Rights Reserved.

10 Useful Free Linux eBooks for Newbies and Administrators25 Hardening Security Tips for Linux Servers60 Commands of Linux : A Guide from Newbies to System Administrator15 Command Line Tools to Monitor Linux Performance5 Best Practices to Secure and Protect SSH Server18 Tar Command Examples in Linux20 Linux YUM (Yellowdog Updater, Modified) Commands25 Useful Basic Commands of APT-GET and APT-CACHE20 Funny Commands of Linux or Linux is Fun in Terminal35 Practical Examples of Linux Find Command10 Linux Distributions and Their Targeted Users

Stay updated. Follow us onfacebook.

Zenity - Creates Graphical (GTK+) Dialog Boxes i... http://www.tecmint.com/zenity-creates-graphical-...

20 of 20 Saturday 12 July 2014 05:09 PM