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

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 <DefaultMergeDirs/>

<!– Test  –>
<!– Scan legacy dirs first, as later items take priority –>
<LegacyDir>/usr/share/applications/test </LegacyDir>
</Menu> <!– End test –>

2) Now go to directory \”/etc/xdg/menus/applications-merged\” and create a new file called \”\” and put the following in the file:


<Name>database</Name> <!– name of the directory in menu –>
<Category>database</Category> <!– This is the category that you need to add in the desktop file.–>


You can include as many directory as you want.

3) 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)

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

[Desktop Entry]
Name=$name – $(basename $i $type)
GenericName=$name – $(basename $i $type)
Exec=xterm -title \”$name – $(basename $i)\” -e \’$exec /tools/pentest/$dir/$(basename $i)\’
##echo $i $dir $cat $type
unset type

And you are done.. Do leave me a comment if you like it.


12 thoughts on “Mod and hack the GNome main menu with automated scripts to create a menu of the directory.”

This site uses Akismet to reduce spam. Learn how your comment data is processed.