Advanced Application Launchers With Zenity
RSS Feed - Comments↴ Author: Jacob Barkdull on Sunday, November 07 2010
If you're like me, you hate when you're in a hurry and just want to start an
application, get right to it, and just start working. Well it never works that
way when you need it to. You have to start the application then navigate to
the directory containing either the various subdirectories or the file(s)
you'll need to work on, before you can even start. Wouldn't it be nice to
just start the application at the navigation stage? Well you can. As well as:
graphically feed text to Espeak or Festival, graphically display a command's
output like a directory listing or a file's contents, graphically start a
web browser at a specific website like a Google search with your input,
and so much more! This is basic BASH and Zenity, so don't worry, it's easy!
All the examples here use one line code that can be placed in a GNOME Panel
Launcher on standard GNOME desktops. Simply copy & paste the code into
a "Custom Application Launcher" on the GNOME Panel. You can do this by
performing a right-click on the GNOME Panel, clicking on "Custom Application
Launcher" and filling in the "Name" area and pasting the code into the
"Program" area.
All the examples here use one line code that can be placed in a GNOME Panel
Launcher on standard GNOME desktops. Simply copy & paste the code into
a "Custom Application Launcher" on the GNOME Panel. You can do this by
performing a right-click on the GNOME Panel, clicking on "Custom Application
Launcher" and filling in the "Name" area and pasting the code into the
"Program" area.-
Start At Navigation Stage
sh -c 'gedit $(zenity --file-selection)'
This example is very useful, it launches a file browsing dialog similar to the default GNOME file browsing dialog. In this example the files you select are sent to the gEdit command, this causes gEdit to open with these files already loaded. This has the same effect as typing "gedit ~/example.txt" into your standard terminal, except with Zenity it's done graphically.
This example isn't limited to gEdit, you can use it with Totem, GIMP, Blender, Cinelerra, or any other program command that normally allows you to launch it from a terminal and open specific files.
-
File and Command Output In Editable Text Box
sh -c 'zenity --text-info --editable --width 500 --height 400 < $(zenity --file-selection)'
You'll notice that in this example I'm using the previous example to graphically select a file I want to read. There's another way of using this same Zenity function, though.
Such as typing in a directory to graphically display it's contents.
sh -c 'zOpen=$(zenity --entry); ls "$zOpen" | zenity --text-info --width 500 --height 400'
Or graphically display a command's output (use carefully.)
sh -c "zOpen=$(zenity --entry); $zOpen | zenity --text-info --width 500 --height 400"
-
Quick Festival / Espeak Text-To-Speech User Interface
For Festival:
sh -c 'zenity --text-info --editable --title "Text-to-Speech" --width 500 --height 300 > /tmp/tts-tmp.txt; festival --tts /tmp/tts-tmp.txt & zenity --info --text "Press OK To Stop" && killall -v audsp'
For Espeak:
sh -c 'eSpeak=$(zenity --text-info --editable --title "Text-to-Speech" --width 500 --height 300); espeak "$eSpeak" & zenity --info --text "Press OK To Stop" && killall -v espeak'
These two examples each open a text box window where you may type or paste text that you would like spoken, hit close, a dialog will appear and -- depending on which one you chose -- either Espeak or Festival will begin to speak the text you entered, when you're done listening -- or you want to interrupt Espeak or Festival -- click 'OK' and they will stop.
-
Simple Text Editor
#!/bin/bash
zOpenPath="$(zenity --file-selection)"
if [ "$zOpenPath" != "" ]
then
zData=$(cat "$zOpenPath")
zNewData=$(echo -n "$zData" | zenity --text-info --editable --width 650 --height 400)
zSavePath=$(echo -n "$(zenity --file-selection --filename="$zOpenPath" --save --confirm-overwrite)")
echo -n "$zNewData" > "$zSavePath"
fi
This example displays a file browsing dialog from which you can select a file to edit, it then opens a text box window where you may type or paste text, when you hit "Close" another file browsing dialog is displayed where you can select the file you'd like to save your modifications to, it can be the original file, a different file, or a non-existent file.
This one is a little more complicated. To use it, you'll have to copy the text above, save it to a file somewhere on your hard drive, and then in the "Custom Application Launcher" window click the "Browse..." button, locate and select the file you just saved and hit "Open".
Make sure the file is executable, by performing a right-click on the file then clicking "Properties", clicking the "Permissions" tab and checking "Allow executing file as program" or executing "chmod 0755 /path/to/file" from a root terminal.
-
Search Google
sh -c 'firefox "http://www.google.com/search?q=$(zenity --entry --text "Search Google")"'
The example above displays a small one line text box window, much like a search box. Typing in this box then clicking 'OK' will open Google Search in a web browser. Currently it's using Firefox as the web browser, but you could change 'firefox' to 'chromium' or any other web browser you'd prefer.
-
Graphically Display System Uptime
sh -c 'zenity --info --text "$(uptime)"'
This one does exactly what it seems like, it displays system "uptime" (how long your systems been booted for) in a little message window. It just makes a useful launcher :)
Share This:
Tweet
Syndication:

Advertisements:

GNU/Linux systems with software you need already installed!

GNU/Linux Tech
Advertise Here
Partners & Friends:



![[frdm] Support SFLC](http://www.softwarefreedom.org/img/support-sflc.png)
Translations (Google)
Česky ·
简体中文 ·
日本語
Español · العربية · Deutsch
русский · 한국어 · Italiano
Français · Português
GNU/Linux systems with software you need already installed!
GNU/Linux Tech
Advertise Here

Español · العربية · Deutsch
русский · 한국어 · Italiano
Français · Português
What Is This Place?
TildeHash is a website for Tech articles
revolving around Free Software
and Unix/Unix-like operating systems,
written by Jacob Barkdull and various contributors,
respectively. Meaning, Free Software (or Open Source); and
GNU/Linux (or simply
Linux),
BSD, OpenSolaris,
or Haiku; respectively. The main goal
of TildeHash is to be different -- the name alone is a little different
(explanation here) -- but
to do it in a useful way.
TildeHash is about discussing Free Software topics that are beneficial to our community, topics that are largely not discussed nor shown. "Free Software" is also often called "Open Source Software". In practice the requirements are identical, although because the term "open" doesn't call to mind freedom, it misses the point.
List of Articles >>
TildeHash is about discussing Free Software topics that are beneficial to our community, topics that are largely not discussed nor shown. "Free Software" is also often called "Open Source Software". In practice the requirements are identical, although because the term "open" doesn't call to mind freedom, it misses the point.
List of Articles >>
