Friday, April 24, 2009

Script to add applications to fvwm-crystal menu

Following script will add applications to fvwm-crystal menu

Screenshot of fvwm-crystal:



#!/bin/bash
APP_BASE=/usr/share/fvwm-crystal/fvwm/Applications
#APP_BASE=~/.fvwm/Applications/

if [[ $1 == '' ]]
then
echo "Usage:"
echo "$0 [icon name]"
exit 0
fi


if [[ ! -e $APP_BASE ]]
then
echo "Menu base does not exists!"
exit 0
#mkdir -p $APP_BASE
fi

MENUS=($( ls $APP_BASE ));
MENU=
APP=$1
APP_NAME=`basename $1`
ICON=$2
SCRIPT=

if [[ `which $APP` == '' && ! -e $APP ]]
then
echo "$APP does not exists!"
exit 0
fi

i=0
while true
do
[[ ${MENUS[$i]} == '' ]] && break;
echo "$i. ${MENUS[$i]}"
i=`expr $i + 1`
done

OPT=''
echo "Enter Menu number to insert item:"
read OPT
if [[ $OPT -lt $i && $OPT -ge 0 ]]
then
MENU=${MENUS[$OPT]}
else
echo "wrong"
fi

if [[ $2 == '' ]]
then
ICON=$APP_NAME
fi

SCRIPT="~$ICON~$APP_NAME"


ANS=""
echo "Menu item: $APP_BASE/$MENU/$SCRIPT"
echo "Continue creating menu item? [y/n]: "
read ANS
if [[ $ANS == 'y' ]]
then
if [[ -e $SCRIPT ]]
then
echo "Script exists!";
else
echo "#!/bin/sh
exec $APP \$@
" > $APP_BASE/$MENU/$SCRIPT
chmod +x $APP_BASE/$MENU/$SCRIPT
fi
else
echo "Not creating menu item!"
fi


Save the script in /usr/bin/fvwm-crystal-menu-gen.sh and make it executable (chmod +x /usr/bin/fvwm-crystal-menu-gen.sh). Use following sytax to add applications to menus

/usr/bin/fvwm_crystal_menu_gen.sh [icon name]


If the application is in PATH you don't have to enter absolute path as just give application name. If you want to acompany an icon with a different name input it in place [icon name]

No comments:

Post a Comment

Intel Corporation XMM7360 LTE Advanced Modem in ArchLinux

The required packages are available in ArchLinux User Repository (AUR) so it will be easier if you can use an AUR helper package like yay . ...