Tuesday, August 23, 2011

How to add new menu to the applications menu in ubuntu

how to add new menu to the applications menu in ubuntu
most of us know that we can add new menu to applications menu by right clicking main menu bar and selecting edit menus.Then a window appears with existing menus and you can add any number of menus and items into them. This is a super simple approach which everyone can follow without much trouble.

But what if you need to edit menus programmatically.Do you know how to do it???
This is the guide for you if you need something like that.

first you need to identify the file which specifies the applications menu in ubuntu.It is applications.menu file located in /etc/xdg/menus/ directory.
locate it and examine bit carefully the tag structure in there.If you are familiar with HTML code tags you will understand it easily.

Follow these steps:
1.Open up a terminal and type sudo nautilus,give password,it will give you a file browser with root privilages. We need root privilages since we are going to edit applications.menu file.

2.open applications.menu file in your favourite text editor.You will see there are tag blocks for development,education,science etc. So what we should do is create our own code block which generates our custom menu. Example code block is given below.

< menu >
< name > MyMenuName < /name >
< directory> myMenu.directory < /directory>
< include>
< and>
< category> custom < /category>
< /and>
< /include>
< /menu>


3.place the above code block in between two existing code blocks. for example in between education and science.
Here is a brief description of what the above code really means:

< name> MyMenuName < name>
This tag defines the name of the menu which is self explanatory.But remember it is not the menu visible name in case we specify a name in myMenu.directory file.if we don't give a name in myMenu.directory file it is the menu visible name.The .directory file is explained in the next step.

<directory> myMenu.directory></directory>
There is a .directory file for each of the menus. So we should create a .directory file for our menu and it's name should be given here.

<include>
<and><
<category>custom></category>
/and>
</include>



This part is really important to understand since this determines which are the applications categorized under this menu.><category>custom></category> line indicates that all the applications which has category of "custom" are put in to this menu.

4.Next step is to create a .directory file for our menu.

example myMenu.directory file

[Desktop Entry]
Name=My apps
Comment=my Applications
Icon=/path/to/icon
Type=Directory
X-Ubuntu-Gettext-Domain=gnome-menus


Name specifies the visible name for our menu.And under icon give the path to the icon.


5.place this myMenu.directory file under /usr/share/desktop-directories.
now you are almost done.

6.The new menu will not visible straight-away since there are no items to display. So you can one of the things to get visible your new menu.

i.create your own debian package with category custom and get install it. After the installation new menu will appear with the new application under it.
If you need help in creating debian packages see the article "How to create debian packages".

ii.change custom to office .then you will see your new menu but with all the office type applications under it.
Here office is used just as an example.

No comments:

Post a Comment