[bash] Enhancing Icon-Handling for TaskBar

Just switched to fvwm a few days ago after many months of not being happy about the style and behaviour of any other window manager. Fvwm is perfect for me, configurable to (nearly) the last detail. I’m still on the way to building the perfect set for me. But I’m on my way.
This is a small bash script, a quick’n’dirty hack (well not so quick to be honest). The script is mainly intended for lazy people - like me - who hate generating menu entries by hand.

It reads all *.desktop files found in /usr/share/applications, compares them to a user configuration file and puts all those icons automagically as shortcuts into the TaskBar. It also resizes the icons (uses imagemagick).

The directory structure (create the directories and files by hand, script doesn’t handle this yet):

The script. name it whatever you want to.

stores the generated 16x16 icons

this file has the generated entries for fvwmtaskbar. You do not have to put anything in it, as the script takes care of this file.

this tells the script which programs to include in the generation. The programms listed in this file are the only ones put in the taskbar. You have to edit this file yourself

this tells the script which programms are seen as “excludes”. This - together with includes - is used to determine new programms. You have to edit this file yourself

Syntax of include and exclude files: One program name per line. The program name is the first part of the *.desktop file name.
Example: mozillafirefox.desktop, so the program name is mozillafirefox. If you have programs you haven’t used yet, the script will display the name of the programs.

And here is the script:

[code]#!/bin/bash

iconscript.sh: Automatically build FvwmTaskBar-Shortcuts from .desktop files

Fvwm is a Window Manager for the X11 Windowing System (http://fvwm.org)

Copyright 2005 Stephen Tallowitz

Released under the GNU General Public Licence (GPL)

Licence available from: http://www.gnu.org/licenses/gpl.txt

Version: 2005-04-25

if you do not get this script to work properly, you may have to install these programs:

gnu coreutils (find, cat, sed)

imagemagick (convert)

things I have yet to do:

1. adhere to handling of config- and cache directories. see http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html

2. write some initialisation routines for fresh “installations” of this script

information on the desktop-files can be found at: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html

set environment

DESKTOP_DIR="/usr/share/applications"
ICON_DIR="/usr/share/pixmaps"

USR_CONFIG="${HOME}/.config/fvwm-iconscript/"

USR_CACHE="${HOME}/.cache/fvwm-iconscript"
FVWM_CONF="${HOME}/.fvwm"

DEBUG=1

Initialise empty cache

echo “” > ${FVWM_CONF}/entries.cache

Remove old, generated icons - deactivated: problems when loading fvwm TaskBar

rm ${USR_CACHE}/*

Read user config for includes

for i in cat ${FVWM_CONF}/iconscript/include; do
for k in find ${DESKTOP_DIR} -name *.desktop | sed -r "s/(.*\/)(.*)(\.desktop)/\2/"; do
if test $i == $k; then
# echo “Name der Desktop-Datei: $i”
executable=cat \find ${DESKTOP_DIR} -name $i.desktop` | sed -n -e “/^Exec/p” | sed -r "s/(.)=(\ )(.)/\3/" # strip any arguments off executable=echo $executable | sed -r "s/(.)\ (.)/\1/" # echo "Name der Exec-Datei: $executable" icon=cat `find ${DESKTOP_DIR} -name $i.desktop` | sed -n -e “/^Icon/p” | sed -r "s/(.)=(\ )(.)/\3/" # echo "Icon-Eintrag: $icon" iconname=echo $icon | sed -r "s/^/(./)+(.)$/\2/" iconpath=echo $icon | sed -r "s/^/(./)+(.){1}$//\1/" echo "Pfad des Icons: $iconpath" echo "Dateiname des Icons: $iconname" if test $iconpath == $iconname; then iconpath="${ICON_DIR}/" fi convert -geometry 16x16 $iconpath$iconname ${USR_CACHE}/16$iconname`
echo “*FvwmTaskBar: Button Icon 16$iconname, Action Exec $executable” >> ${FVWM_CONF}/entries.cache
fi
done
done

Read includes and excludes and print new desktop-files

for i in find ${DESKTOP_DIR} -name *.desktop | sed -r "s/(.*\/)(.*)(\.desktop)/\2/"; do
value=“true”
for k in cat ${FVWM_CONF}/iconscript/include ${FVWM_CONF}/iconscript/exclude; do
if test $i == $k; then
value=“false”
fi
done
if test $value == “true”; then
echo “New Desktop entry file for: $i”
fi
done
[/code]

The things you might want to change in your .fvwm/config (assuming you know the script by ~/.fvwm/iconscript.sh):

ImagePath ${HOME}/.cache/fvwm-iconscript/

AddToFunc InitFunction
+ I Module FvwmTaskBar
+ I Exec exec ${HOME}/.fvwm/iconscript.sh

AddToFunc RestartFunction
+ I Module FvwmTaskBar
+ I Exec exec ${HOME}/.fvwm/iconscript.sh

# Read the file the script produced
Read entries.cache
# Some manual entries that are not handled by the script
*FvwmTaskBar: Button Icon /usr/somewhere/xterm.xpm, Action (Mouse 1) exec xterm

Anyone like this idea?

One small side note: the icon handling from the *.desktop config files is rather simple. Some shortcuts may not display an icon. If they don’t you will mostly find it to be a path / filename problem. I am working on this. Believe me, I’m not happy about it myself. So just wait a little bit longer until I fix it. (fixed on: 2005-05-01)

cheers,
geta

I’ve continued working on the script. It does handle most desktop-files properly now. By using find it has become much slower, however. So watch out if you’re planning on putting this script in your .fvwm/config

[code]#!/bin/bash

Automatically build FvwmTaskBar-Shortcuts from .desktop files

Fvwm is a Window Manager for the X11 Windowing System (http://fvwm.org)

Copyright 2005 Stephen Tallowitz

Released under the GNU General Public Licence (GPL)

Licence available from: http://www.gnu.org/licenses/gpl.txt

Version: 2005-05-01

if you do not get this script to work properly, you may have to install these programs:

gnu coreutils (find, cat, sed)

imagemagick (convert)

things I have yet to do:

1. adhere to handling of config- and cache directories. see http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html

2. write some initialisation routines for fresh “installations” of this script

information on the desktop-files can be found at: http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-0.9.4.html

set environment

DESKTOP_DIR="/usr/share/applications"
ICON_DIR="/usr/share/pixmaps"

USR_CONFIG="${HOME}/.config/fvwm-iconscript/"

USR_CACHE="${HOME}/.cache/fvwm-iconscript"
FVWM_CONF="${HOME}/.fvwm"

DEBUG=“true”

Initialise empty cache

echo “” > ${FVWM_CONF}/entries.cache

Remove old, generated icons - deactivated: problems when loading fvwm TaskBar

rm ${USR_CACHE}/*

Read user config for includes

for i in cat ${FVWM_CONF}/iconscript/include; do
for k in find ${DESKTOP_DIR} -name *.desktop | sed -r "s/(.*\/)(.*)(\.desktop)/\2/"; do
if test $i == $k; then
# echo “Name der Desktop-Datei: $i”
executable=cat \find ${DESKTOP_DIR} -name $i.desktop` | sed -n -e “/^Exec/p” | sed -r "s/(.)=(\ )(.)/\3/" # strip any arguments off executable=echo $executable | sed -r "s/(.)\ (.)/\1/" # echo "Name der Exec-Datei: $executable" icon=cat `find ${DESKTOP_DIR} -name $i.desktop` | sed -n -e “/^Icon/p” | sed -r "s/(.)=(\ )(.)/\3/" # echo "Icon-Eintrag: $icon" iconname=echo $icon | sed -r "s/^(.){0,2}/(./)+(.)$/\3/" iconpath=echo $icon | sed -r "s/^(.){0,2}/(./)+(.){1}$//\2/" echo "DEBUG: path of icon: $iconpath" echo "DEBUG: filename of icon: $iconname" if test $iconpath == $iconname; then # find all icons in /usr/share # 2>/dev/null suppresses permission errors, see http://www.issociate.de/board/post/202393/find.html cont="true" for l infind /usr/share/ -name $iconname* 2>/dev/null | egrep ".*(png|xpm)"; do echo "DEBUG: name of icon file: $l" if test -e $l; then echo "DEBUG: file $l exists" icon=$l cont="false" fi if test $cont=="false"; then echo "DEBUG: interrupted loop" break; fi done fi convert -geometry 16x16 $icon ${USR_CACHE}/16$iconname`
echo “*FvwmTaskBar: Button Icon 16$iconname, Action Exec $executable” >> ${FVWM_CONF}/entries.cache
fi
done
done

Read includes and excludes and print new desktop-files

for i in find ${DESKTOP_DIR} -name *.desktop | sed -r "s/(.*\/)(.*)(\.desktop)/\2/"; do
value=“true”
for k in cat ${FVWM_CONF}/iconscript/include ${FVWM_CONF}/iconscript/exclude; do
if test $i == $k; then
value=“false”
fi
done
if test $value == “true”; then
echo “New Desktop entry file for: $i”
fi
done
[/code]

Cheers,
geta