Menu editor

John S. Skogtvedt jss2k2 at chello.no
Sun Jan 11 13:46:27 EST 2004


Why isn't there a menu editor for Openbox3? It can hardly be much work, seeing as openbox3 parse a lot of xml already. I got tired of manually editing menu.xml a couple of months ago, so I wrote a bash script to add entries to the menu. It's far from perfect...It only lets you add a entry to the end of a submenu, and it seems to kill off newlines between submenus. It works by figuring out where the end of the submenu is, go one line up, and then copying the menu up until that point into an array. It adds a entry, and then copies the rest of the menu into that array, and writes it to menu.xml. If anyone's interested, it's attached (And copied in below, just in case). I'm posting it hoping someone will get annoyed at how ugly it is, and write a real menu editor. ;)

#!/bin/bash
ob3menu="$HOME/.config/openbox/menu.xml"
IFS="
"
menu=( `cat $ob3menu` )

[ "$1" = "manual" ] && exec ${EDITOR-gvim} ${ob3menu}

for ((i=0, a=0; i <= ${#menu[@]}; i++))
do
	if [[ "${menu[i]}" = "<menu id="*"label="* ]]
	then
		alt[$a]=${menu[i]}
		echo $[a+1] ${menu[i]}
		(( a++ ))
	fi
done

while [ -z $num ]
do
	echo -n "Menu: "
	read num
done

menuid=${alt[num]}

for ((i=0; i <= ${#menu[@]}; i++))
do
	if [[ ${menu[i]} = $menuid* ]]
	then
		s=$i
	fi
done
(( s-- ))

for ((i=0; i < s; i++))
do
	tmp[$i]=${menu[i]}
done

w1="  "
w2="    "
echo

while [ -z $app ]
do
read -p "App name: " app
done

while [ -z $exec ]
do
read -p "App exec: " exec
done

tmp[$i]="${w1}<item label=\"$app\">"
(( i++ ))
tmp[$i]="${w2}<action name=\"Execute\"><execute>$exec</execute></action>"
(( i++ ))
tmp[$i]="${w1}</item>"
(( i++ ))

for ((a=i, i=s; i <= ${#menu[@]}; a++,i++))
do
	tmp[$a]=${menu[i]}
done

{
for ((i=0; i <= ${#tmp[@]}; i++))
do
	echo ${tmp[i]}
done
} > $ob3menu
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ob3menu.sh
Type: application/x-shellscript
Size: 977 bytes
Desc: not available
URL: <http://icculus.org/pipermail/openbox/attachments/20040111/76f33a57/attachment.bin>


More information about the openbox mailing list