Mod and hack the GNome main menu with automated scripts to create a menu of the directory.
Problem:
I had a directory with very good collection of my scripts and very organized in folders. The structure is something like this, first I have the broad classification of the category. Then I have the name of the tool/script as the name of the directory. All these are perl/python or shell scripts and luckily labelled so with the extension. I want to add these to the GNome main (Applications) menu.
Solution:
Lets take it stepwise:
1) Add new menu tools to the Applications menu. Go to /etc/xdg/menus
Open the file applications.menu and add the following before
<!– Test –>
- Now go to directory ”/etc/xdg/menus/applications-merged” and create a new file called ”test-categories.menu” and put the following in the file:
You can include as many directory as you want.
- Now the fun part of creating the desktop files that link to the perl/python or the shell scripts and actually populate the menu. Note: Until the menu contains any item, the menu will not appear. Okay, go to directory ”/usr/share/applications/test”. Create a shell script with the following and run it in the directory containing your scripts, and then ”mv *.desktop /usr/share/applications/test”:
for i in $(find . -type f -executable)
do##Get the directory name from the full path
dir=$(dirname $i)
cat=$(echo $dir|awk -F/ '{print $2}’)
name=$(echo $dir|awk -F/ '{print $3}’)## Find the type of the file
[[ ”${i}” =~ sh$ ]] && type=sh;
[[ ”${i}” =~ pl$ ]] && type=pl;
[[ ”${i}” =~ py$ ]] && type=py;
if [[ ”$type” = ”pl” ]]
then
exec=perl
elif [[ ”$type” = ”sh” ]]
then
exec=bash
else
exec=python
fi
[[ ”${type}” =~ ^$ ]] || (
##echo ”creating file”
cat «EOF >test_$(basename $i).desktop[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=$name – $(basename $i $type)
GenericName=$name – $(basename $i $type)
Exec=xterm -title ”$name – $(basename $i)” -e ’$exec /tools/pentest/$dir/$(basename $i)’
Terminal=true
Categories=$cat
EOF
)
##echo $i $dir $cat $type
unset type
done
And you are done.. Do leave me a comment if you like it.<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="http://blog.amit-agarwal.co.in/wp-content/uploads/2010/08/pixy6.gif" alt="" />
Related Articles:
- 2010/01/21 shotwell- Photo organizer for Linux in Gnome
- 2010/01/13 Speed up gnome and change widow manager for gnome.
- 2009/12/08 C Prog to change wallpaper in every 30 seconds.
- 2009/12/02 gnome-shell and gnome-do on F11 Screenshots