Mod and hack the GNome main menu with automated scripts to create a menu of the directory.

2010-03-04 344 words 2 mins read

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  –>

Test /usr/share/applications/test X-GNOME-test.directory database
  1. Now go to directory &#8221;/etc/xdg/menus/applications-merged&#8221; and create a new file called &#8221;test-categories.menu&#8221; and put the following in the file:
Applications Pentest database **** pentest-database.directory database ****

You can include as many directory as you want.

  1. 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 &#8221;/usr/share/applications/test&#8221;. Create a shell script with  the following and run it in the directory containing your scripts, and then &#8221;mv *.desktop /usr/share/applications/test&#8221;:

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}&#8217;)
name=$(echo $dir|awk -F/ '{print $3}&#8217;)

## Find the type of the file
[[ &#8221;${i}&#8221;  =~ sh$ ]] && type=sh;
[[ &#8221;${i}&#8221;  =~ pl$ ]] && type=pl;
[[ &#8221;${i}&#8221;  =~ py$ ]] && type=py;
if [[ &#8221;$type&#8221; = &#8221;pl&#8221; ]]
then
exec=perl
elif [[ &#8221;$type&#8221; = &#8221;sh&#8221; ]]
then
exec=bash
else
exec=python
fi
[[ &#8221;${type}&#8221; =~ ^$ ]] || (
##echo &#8221;creating file&#8221;
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 &#8221;$name – $(basename $i)&#8221; -e &#8217;$exec /tools/pentest/$dir/$(basename $i)&#8217;
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="" />


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it