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

2010-03-04 379 words 2 mins read

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.
Lets take it stepwise:
1)  Add new menu tools to the Applications menu. Go to /etc/xdg/menus
Open the file and add the following before

<!– Test  –>

Test /usr/share/applications/test database
  1. Now go to directory &#8221;/etc/xdg/menus/applications-merged&#8221; and create a new file called &#8221;; and put the following in the file:
Applications Pentest database **** 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)

##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; ]]
elif [[ &#8221;$type&#8221; = &#8221;sh&#8221; ]]
[[ &#8221;${type}&#8221; =~ ^$ ]] || (
##echo &#8221;creating file&#8221;
cat «EOF >test_$(basename $i).desktop

[Desktop Entry]
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;
##echo $i $dir $cat $type
unset type

And you are done.. Do leave me a comment if you like it.<div class="zemanta-pixie"><img class="zemanta-pixie-img" src="" alt="" />


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