[Linux] Scripting with xfce4-panel's "Generic Monitor" applet


You're a slave to the money then you die
Scripting on the xfce4-panel
The xfce4-panel is extremely customizable, offering a wide variety of applets and addons to satisfy the user's needs.

HOWEVER, if you truly desire to make the panel your own, the most important applet, in my opinion atleast, is the Generic Monitor applet.

All it takes is minutes of basic scripting knowledge to transform your panel with this simple applet.

Here's an example using my setup:

Starting with a brand new panel:

Click → + (Add new item to panel)
Search → "Generic Monitor"
Click → Add

You should now see the default text for the applet on your bar (genmon)XXX
Right-click → "(genmon)XXX" → Select "Properties"

Now the magic happens.
For starters, you can try simple shell commands such as uname -r.
These less complex commands such as uname -r may be ran without the creation of an external shell script.

Now let's increase the complexity.

We need a place to store our more complex scripts, I'm going to choose a directory called ~/.genmonscripts, you can use any location and name you wish as long as it's accessible to your linux user.
mkdir ~/.genmonscripts && cd ~/.genmonscripts
touch freemem.sh
The main idea is to perform your work in the script and finally echo or print out the string you wish to display on the xfce4-panel.
# create variable FREE_MEM, then pipe data from free -h into awk which selects the part of the text you would want
FREE_MEM=`free -h | awk '/^Mem:/ {print $3 "/" $2}'`
echo "ram $FREE_MEM  "
# printed out to panel
Once you have the script written, we can test if it works on our panel.
Note: the ~ alias will not work, you must use the real path. (typically /home/yourusername/)

sh /home/griimnak/.genmonscripts/freemem.sh
(don't forget sh at the beginning)

And that's basically it!
This may seem simple, but someone with advanced scripting knowledge could do some really impressive things with this applet.
For example, you could write a script that checks how many new emails you have, etc.

Linting your scripts
Linting your scripts are just generally considered good practice and minimize memory leaks from inefficient or invalid scripts.

Download and install [ To view this link you must register here. ]

[ To view this link you must register here. ] is a static linting tool for shell scripts.
Installation guide: [ To view this link you must register here. ]

My scripts
To assist you further with understanding how to write scripts for genmon, i'll be providing the scripts i personally use.

name: cputemp.sh
desc: returns the temp of the cpu package
useage: sh cputemp.sh

if which sensors > /dev/null; then
    sensors | grep Core | awk '{print $3;}' | grep -oEi '[0-9]+.[0-9]+' | awk '{total+=$1; count+=1} END {print total/count,"C  "}'

name: sysload.sh
desc: returns both current cpu usage % and used ram/maxram ratio in one string.
usage: sh sysload.sh
CPU=`eval $(awk '/^cpu /{print "previdle=" $5 "; prevtotal=" $2+$3+$4+$5 }' /proc/stat); sleep 0.4; eval $(awk '/^cpu /{print "idle=" $5 "; total=" $2+$3+$4+$5 }' /proc/stat); intervaltotal=$((total-${prevtotal:-0})); echo "$((100*( (intervaltotal) - ($idle-${previdle:-0}) ) / (intervaltotal) ))"`
FREE_MEM=`free -h | awk '/^Mem:/ {print $3 "/" $2}'`
printf "cpu %.f%%  " $CPU
echo "ram $FREE_MEM  "

name: netload.sh
desc: returns current network usage (up and down)
usage: sh netload.sh <adapter>
Note: Set update interval to 1.6 or above on genmon

if [ -z "$1" ]; then
    echo usage: $0 network-interface
    echo e.g. $0 eth0


R1=`cat /sys/class/net/$1/statistics/rx_bytes`
T1=`cat /sys/class/net/$1/statistics/tx_bytes`
sleep 1
R2=`cat /sys/class/net/$1/statistics/rx_bytes`
T2=`cat /sys/class/net/$1/statistics/tx_bytes`
TBPS=`expr $T2 - $T1`
RBPS=`expr $R2 - $R1`
TKBPS=`expr $TBPS / 1024`
RKBPS=`expr $RBPS / 1024`
printf "%s: ↓%dK ↑%dK  " $1 $RKBPS $TKBPS
Hopefully this was useful to someone out there, Happy scripting!
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)