CentOS 6.8 – Script Adding Top Panel Applets – GEyes, ShowDesktop and Gnome Monitor

Introduction

Please see the article “Build a Linux-based Infrastructure Solution Demonstration Series” (http://blogs.czapski.id.au/2016/10/build-a-linux-based-infrastructure-solution-demonstration-series) for rationale, introduction and links to articles in this series.

In this article a script which will add GEyes, ShowDesktop and GnomeMonitor applests and configure the GnomeMonitor applet will be developed and executed.

Pre-Requisites

This article assumes that

  1. The work is done in the Virtual Box Machine Image created in accordance with the instructions in the blog article to be found at http://blogs.czapski.id.au/2016/10/configure-virtual-box-virtual-machine-and-install-centos-6-8-base-image.

The instructions should work in other RedHat 6-like OS’ and OS versions.

Script Adding Applets to Top Panel

I typically set up my environment to my taste, which does not mean that everybody needs to do this the same way or at all.

The discussion below shows how one can script adding and configuration of top panel applets.

Remember that all this can be done using the relevant UIs but my objective is to create configuration scripts which I can execute and have the demo image configured without having to tediously manipulate various UIs.

Let’s have a look at some applets-related commands and outputs, and then create and execute a script to add three applets to the top panel using a script.

After CentOS installation the top panel looks like that shown in the figure below.

037_centos_top_panel_before

Let’s list top level panels so as to see which ones we have – top and bottom is what is expected.

/usr/bin/gconftool-2 --all-dirs /apps/panel/toplevels

/apps/panel/toplevels/top_panel
/apps/panel/toplevels/bottom_panel

List applets in the two panels

/usr/bin/gconftool-2 --all-dirs /apps/panel/applets

/apps/panel/applets/trash_applet
/apps/panel/applets/workspace_switcher
/apps/panel/applets/window_list
/apps/panel/applets/fast_user_switch_applet
/apps/panel/applets/systray
/apps/panel/applets/gnote
/apps/panel/applets/clock

List all available applets which can be added to the panels

/usr/bin/activation-client -q --spec="has (repo_ids,'IDL:Bonobo/Control:1.0')" | grep '^IID' | cut -d ',' -f1-1 | cut -d ' ' -f2-2 | more

OAFIID:GNOME_MixerApplet
OAFIID:DwellClickApplet
OAFIID:GNOME_SystemTrayApplet
OAFIID:GNOME_NotificationAreaApplet
OAFIID:GNOME_Panel_TrashApplet
OAFIID:GNOME_ClockApplet
OAFIID:GNOME_AccessxStatusApplet
OAFIID:Invest_Applet
OAFIID:GnoteApplet
OAFIID:GNOME_MailcheckApplet
OAFIID:GNOME_CDPlayerApplet
OAFIID:GNOME_FishApplet
OAFIID:GNOME_GeyesApplet
OAFIID:GNOME_GtikApplet
OAFIID:GNOME_WindowMenuApplet
OAFIID:GNOME_KeyboardApplet
OAFIID:GNOME_GWeatherApplet
OAFIID:GNOME_BattstatApplet
OAFIID:GNOME_PagerApplet
OAFIID:GNOME_WorkspaceSwitcherApplet
OAFIID:GNOME_TasklistApplet
OAFIID:GNOME_MultiLoadApplet
OAFIID:GNOME_StickyNotesApplet
OAFIID:GNOME_ShowDesktopApplet
OAFIID:GNOME_WindowListApplet
OAFIID:GNOME_DriveMountApplet
OAFIID:GNOME_CharpickerApplet
OAFIID:GNOME_DictionaryApplet
OAFIID:GNOME_FastUserSwitchApplet
OAFIID:GNOME_GDictApplet
OAFIID:PointerCaptureApplet
OAFIID:GNOME_BrightnessApplet
OAFIID:Square_Controller
OAFIID:Circle_Controller
OAFIID:Bonobo_Sample_Entry
OAFIID:GNOME_CPUFreqApplet
OAFIID:GNOME_MiniCommanderApplet

Create the script to update property values in the applet dump file. This script will be used later to update specific key values. If you are curious, execute the script lines one at a time to see what they do.

mkdir -p /media/sf_distros/scripts
cat <<-'EODECK' > /media/sf_distros/scripts/z_update_upplet_config_key.sh
#!/bin/bash
# update value for key in applet dump for a particular applet
# expect applet dump file, key and value pair as $1, $2 and $3
fileName=${1}
keyName=${2}
valueName=${3}
echo -- before : processing ${fileName}, key: ${keyName}, for value ${valueName}
cat ${fileName} | grep -A 2 "${keyName}<"
matchedLine=$(cat ${fileName} | grep -n "${keyName}<")
matchedLineNum=$(echo ${matchedLine} | cut -d ':' -f 1)
replaceLineNum=$(echo $(( ${matchedLineNum} + 3)))
sed -i "${replaceLineNum}s|<\([a-z]*\)>.*</\([a-z]*\)>|<\1>${valueName}</\1>|" ${fileName}
echo ++ after
cat ${fileName} | grep -A 2 "${keyName}<"
EODECK
chmod ug+x /media/sf_distros/scripts/z_update_upplet_config_key.sh

Create a script which will add three applets to the top bar and configure the monitor applet

mkdir -p /media/sf_distros/scripts
cat <<-'EODECK' > /media/sf_distros/scripts/005_add_applets_to_top_panel.sh
# Add GEyes to the top bar
/usr/libexec/gnome-panel-add --applet=OAFIID:GNOME_GeyesApplet --panel=top_panel --position=849 --copy-launcher

# Add Show Desktop Applet to the top bar
/usr/libexec/gnome-panel-add --applet=OAFIID:GNOME_ShowDesktopApplet --panel=top_panel --position=400 --copy-launcher

# Add Monitor Applet to the top bar
/usr/libexec/gnome-panel-add --applet=OAFIID:GNOME_MultiLoadApplet --panel=top_panel --position=980 --copy-launcher

# Dump applet_2 configuration - that will be the last applet added above - MultiLoadApplet
sleep 2
gconftool-2 --dump /apps/panel/applets/applet_2 > ~/applet_2_fix.entries
sleep 2

# Update property values and load the updated entries
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries view_netload true
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries view_diskload true
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries view_loadavg true
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries view_swapload true
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries view_memload true
/media/sf_distros/scripts/z_update_upplet_config_key.sh ~/applet_2_fix.entries size 30

gconftool-2 --load ~/applet_2_fix.entries
killall gnome-panel

EODECK
chmod ug+x /media/sf_distros/scripts/005_add_applets_to_top_panel.sh

Execute the commands

/bin/bash -v /media/sf_distros/scripts/005_add_applets_to_top_panel.sh

After script execution the top panel looks like the following

038_centos_top_panel_after

List the applets now in the panels

/usr/bin/gconftool-2 --all-dirs /apps/panel/applets
 /apps/panel/applets/clock
 /apps/panel/applets/applet_0
 /apps/panel/applets/applet_1
 /apps/panel/applets/applet_2
 /apps/panel/applets/trash_applet
 /apps/panel/applets/window_list
 /apps/panel/applets/systray
 /apps/panel/applets/workspace_switcher
 /apps/panel/applets/gnote
 /apps/panel/applets/fast_user_switch_applet

It is expected that the image being configured a bit at a time will be created multiple times. With this assumptions the individual scripts are appended to a single script so that the second and subsequent images can be configured by a single script rather than having lots of scripts to execute manually.

Append “add applets to top panel and configure monitor” script execution commands to the initial bulk configuration script. This script is intended to collect all automated configuration commands and scripts so that they can be all executed in one go on a brand new image if one gets to do this the second and subsequent times.

Don’t actually execute this script while you are building the first image.

cat <<-'EODECK' >> /media/sf_distros/scripts/000_initial_bulk_configuration.sh
# add and configure top panel applets
/bin/bash -v /media/sf_distros/scripts/005_add_applets_to_top_panel.sh

EODECK
chmod ug+x /media/sf_distros/scripts/000_initial_bulk_configuration.sh

Leave a Reply

Your email address will not be published. Required fields are marked *