Create Gnome Menu
Entries via Shell Script
I have seen this question asked frequently on the Ubuntu forums. This page will
teach you how. You as a user can make your own menu entry by right clicking on
the menu icon in the upper left corner and selecting Edit Menus. This bring up
a GUI an you can select which section to install the menu item in. We want to
create one via a shell script.
All menu items are stored in the
/usr/share/applications
folder. In that folder there will be a .desktop file for each menu entry. Lets
get into those .desktop files shall we?
Here is an example of the contents of a .desktop file:
What the following code does is make a menu entry called Kompozer in the
Programming section of the Gnome menu.
[Desktop Entry]
Encoding=UTF-8
Version 1.0
Name=Kompozer
Name[ja]=Kompozer
Name[de]=Kompozer
Comment=Create and Edit Web Pages
Categories=GNOME;Application;Development;
Exec=/usr/bin/kompozer
Icon=/opt/kompozer/icons/mozicon50.xpm
Terminal=false
Type=Application
This file could be called
kompozer.desktop
and would be stored in
/usr/share/applications.
Lets go through each line.
The first three line should be te same no matter what you do:
[Desktop Entry]
Encoding=UTF-8
Version 1.0
The nex tline is the name of the menu entry. Thie will be the name of the menu
entry.
Name=Kompozer
The next two lines are optional, as they are for other languages, Default is
English. and this line is optional if you have English installed.
Name[ja]=Kompozer
Name[de]=Kompozer
The next line is a comment for when you place your mouse over the menu item a
little floating text box pops up. This is optional.
Comment=Create and Edit Web Pages
The next line is really important as this is which section of the menu you will
install the entry into. You must make sure the first word is
Categories
then followed by
GNOME;Applications;.
Remember, the
semicolon (;) at the end is
very important.
Categories=GNOME;Application;Development;
Now if you wish to select the category use the following chart:
Accessories --> Utility;
Edutainment --> Education;
Games --> Game;
Graphics --> Graphics;
Internet --> Network;
Office --> Office;
Programming --> Development;
Sound & Video -->AudioVideo;
System Tools --> System;
Others --> Other;
Making a line example: Catagories=GNOME;Applications;Office; would place the
menu item in the Office section.
The next line is very important as it is the executable for the application.
After the Exec put the location of the executable or shell script for the
application.
Exec=/usr/bin/kompozer
The next line determines what icon the menu item uses. After the Icon put the
path to where the icon image is located. If no icon is chosen then a simple
square will be put in its place.
Icon=/opt/kompozer/icons/mozicon50.xpm
The next line will determine if the application will or will not run in a
terminal. Either true or false are the only valid entries. GUI applications
don't normally run in a terminal.
Terminal=false
The next line tells Ubuntu that you are wanting to run an application:
Type=Application
That should do it for .desktop menu syntax. When I create a shell script to
create menu entries I use the echo command and redirection. Here is an example:
sudo echo "[Desktop Entry]" > /usr/share/applications/kompozer.desktop
sudo echo "Encoding=UTF-8" >> /usr/share/applications/kompozer.desktop
sudo echo "Version 1.0" >> /usr/share/applications/kompozer.desktop
sudo echo
"Name=Kompozer" >> /usr/share/applications/kompozer.desktop
.
.
.
The first ">" will create a text file and each corresponding ">>" will append to
the end of the text file. When the script is run your menu entry will be
created. Some systems you will need to restart the workspace to see the new
menu entry appear.
I hope this procedure helps.