Tech Tip: Use gxmessage for Displaying GUI Messages from Scripts
There are many dialog programs out there, Zenity, Kdialog, xdialog, etc. I love programs like these. They make it so easy to spice up a shell script with a little GUI action. Today I'm going to go look at a dialog program called gxmessage.
I just recently got a Nokia N900 (Every Linux user should get one) and while playing with it I found that a few programs on it were calling gxmessage to create a user interface. I found that it seemed to have a number of options and seemed easy to use. So I jumped on to my laptop and did a search through the repositories for it. I found it in a package called "gmessage". To install it just do the following:
sudo aptitude install gmessage
You can use this one line code to produce a GUI dialog with buttons:
gxmessage -center \ -buttons "This is my button":1,"This is my other button":2 \ -title "This is my dialog BOX" 'Linux is great!!!'
One of the nice features that gxmessage has, that some others don't, is the ability to choose the size of the dialog box using the "-geometry" switch.
gxmessage -center \ -buttons "This is my button":1,"This is my other button":2 \ -geometry 190x80 \ -title "This is my dialog BOX" 'Linux is great!!!'
Gxmessage will restrict you from making your dialog to0 small for the componets you have placed in it. For example, if you set the geometry to 10x10 and the dialog needs at lest 100x50 to display all your buttons and messages it will override your 10x10 and default to 100x50.
For each button you create you can asign it a numeric value which is indicated by placeing a colon after the buttons message followed by the numeric value you wish to asign to it. You can then grab the value of the button being pressed and use it to continue your script. Here is a short example:
#!/bin/bash gxmessage -center \ -buttons "Yes":1,"Of Course":2 \ -geometry 290x80 \ -title "Linux Journal Question" 'Does Shawn Powers ROCK?' answer=$? case "$answer" in 1) gxmessage -center "You said 'YES'" ;; *) gxmessage -center "I agree, Of Course." ;; esac
I've only touched the surface here of what you can do with gxmessage, look through the man pages for more.
Fast/Flexible Linux OS Recovery
On Demand Now
In this live one-hour webinar, learn how to enhance your existing backup strategies for complete disaster recovery preparedness using Storix System Backup Administrator (SBAdmin), a highly flexible full-system recovery solution for UNIX and Linux systems.
Join Linux Journal's Shawn Powers and David Huffman, President/CEO, Storix, Inc.
Free to Linux Journal readers.Register Now!
- The Italian Army Switches to LibreOffice
- Download "Linux Management with Red Hat Satellite: Measuring Business Impact and ROI"
- Petros Koutoupis' RapidDisk
- Linux Mint 18
- Oracle vs. Google: Round 2
- The FBI and the Mozilla Foundation Lock Horns over Known Security Hole
- Varnish Software's Varnish Massive Storage Engine
- Privacy and the New Math
- Ben Rady's Serverless Single Page Apps (The Pragmatic Programmers)
Until recently, IBM’s Power Platform was looked upon as being the system that hosted IBM’s flavor of UNIX and proprietary operating system called IBM i. These servers often are found in medium-size businesses running ERP, CRM and financials for on-premise customers. By enabling the Power platform to run the Linux OS, IBM now has positioned Power to be the platform of choice for those already running Linux that are facing scalability issues, especially customers looking at analytics, big data or cloud computing.
￼Running Linux on IBM’s Power hardware offers some obvious benefits, including improved processing speed and memory bandwidth, inherent security, and simpler deployment and management. But if you look beyond the impressive architecture, you’ll also find an open ecosystem that has given rise to a strong, innovative community, as well as an inventory of system and network management applications that really help leverage the benefits offered by running Linux on Power.Get the Guide