2014-03-18

Adding your own menu item and command in Main Menu


Pranaam to all bhai ji _/\_
first of all warm hugs to Hardeep singh and zero cool who helped me in this tutorial because without these guys it was not possible for me _/\_

Today i am going to discuss , how to add your own menu item in ubuntu default menu(gnome 2)
the process is not only limited to ubuntu only but also you can use it for other linux distros too(fedora/centos/redhat etc) too.
lets start :)

i am logged in ubuntu(Backtrack) .
for menu editing we need following things
1. edit file /etc/xdg/menus/applications.menu
2. need to create your_menu.directory file under directory /usr/share/desktop-directories.
3.need to create a file 'your_command.desktop' under directory /usr/share/applications.
4. add menu entry

ok , first of all i am going to show you editing of main menu file (/etc/xdg/menus/applications.menu)


in this file , we need to define following things ,
a). menu name
b). a directory file which holds menu item name and its icon
c). include tag
d). category name in which our sub menu item will be consider for menu
e). and last one is
f). command file

Here is the menu code that we need to place in applications.menu file


here is the code

<Menu>
     <Name>indishell Lab</Name>
      
       <Directory>lab.directory</Directory>
          
          <Include>
          
             <Category>lab</Category>
          
              <Filename>command.desktop</Filename>
          
          </Include>
</Menu> 
 
lets discuss about parameters defined in above code
<Menu> tag is start of menu item

 <Name>indishell Lab</Name>
this is the name tag for menu item, put whatever you want in between <Name>  </Name> tags
i am going to name this menu as indishell Lab, so mine one is
<Name>indishell Lab</Name>

after that we need to define .directory file which holds our menu item name and icon
you can name this directory file as any_name.directory , i am naming it as lab.directory
<Directory>lab.directory</Directory>
we need to create .directory file  in directory /usr/share/desktop-directories
with name lab.directory
and content will be like this


here is the code of  my lab.directory file


[Desktop Entry]
Type=Directory
Name=IndiShell Lab
Comment=my menu
Icon=/root/cbi.jpg
X-Ubuntu-Gettext-Domain=gnome-menus


here essential fields are
Name 
Icon
name field is responsible for name that will be consider for your menu item in menu 
i want to create menu item with name "IndiShell Lab" thats why Name=IndiShell Lab
Icon field is for defining icon that will appear in menu item , just give its full path and that image must be in a directory which has read permission
i am going to use an image which is saved in /root directory and its name is cbi.jpg
so its, Icon=/root/cbi.jpg

edit this code as per your requirement and save this file under directory /usr/share/desktop-directories
note:- file name must be same as you defined in menu (  <Directory>lab.directory</Directory> )
else menu file wont load it xD

 

ok now moves to command file 
once you have done with menu item name file , now we can add our command under that menu
lets go for it ;)



<Include>
          
             <Category>lab</Category>
          
              <Filename>command.desktop</Filename>
          
          </Include>

this code is for defining category name and then including our command file
you can define category name according to your wish, i am defining it as 'lab'
and now need to include a file which will act as program launcher ^_^
this file consist name for command launcher , command to launch program/ or to execute any command 
for example , i want to create a launcher for command   "top"  (top command is use to show processes with CPU load and RAM memory usage )
code of my command.desktop file is 


[Desktop Entry]
Name=running processes
Encoding=UTF-8
Comment=to check running processes
Exec=bash -c "top;sudo -s"
Icon=flag.png
Terminal=true
Type=Application
Categories=lab;




here "Name" is the name that will be appear on launcher
you can  chose whatever you want
Exec=bash -c "top;sudo -s"
Exec= this is the main part , this field represent command that has to run
i want to run command "top" in terminal
here bash -c is for , use bash binary and -c stands for command
run command with bash shell ;)
bash -c "top;sudo -s"
bash shell command top ; keep open shell terminal
sudo -s command will keep shell terminal open
means
command  will do
use bash shell (bash) and run command (-c) top and another command(;) in which just an interactive shell will be executed (sudo -s )
 you can use any command that you want to run via this launcher
like you want to run command whoami using this launcher
value for Exec will be
bash -c "whoami ;sudo -s"


Icon=flag.png
Terminal=true
Type=Application
Categories=lab;

Icon field is just for icon that you want to show on the launcher 
either give full path of icon or just put it in directory /usr/share/pixmaps and  supply name of image(in mine case its flag.png)

Terminal this field is for defining whether you want to run command in shell terminal or not
if value is 'true', means you want to run command in shell. 'false' means you dont want to run command in shell.
Categories this is very necessary field which we need to define and value of this field must be same as  menu category in which you are going to include this command launcher file
<Category>lab</Category>
          
              <Filename>command.desktop</Filename>

remember something ??? :D
thats why value in this field is lab
if 
<Category>lab</Category>
had like this 
<Category>icalab</Category>
then value in Categories field in file command.desktop would be icalab instead of lab

ok now save this file (command.desktop ) in directory /usr/share/applications



file will not appear with the name as we used while saving , file will appear with the name that we defined in name field i.e
[Desktop Entry]
Name=running processe
3:)

ok now time to check whether we got our menu item in menu or not >:D<



so this is how we can edit main menu and can add our menu item in menu ^_^

Thank you
Greetz to :-
Zero cool ,code breaker ica, Aasim shaikh,Reborn,lord crusi, Raman kumar rana,INX_r0ot,Darkwolf indishell, lord crusi, Chinmay Pandya ,Silent poison India,Magnum sniper,Atul Dwivedi,ethicalnoob Indishell,Local root indishell,Irfninja indishell,Hardeep bhai,Mannu,Viki , AR AR bhai ji, Anju,RR mam and Deepika kaushik







Share this post

3 comments

  1. Nice .. n well explained !

    ReplyDelete
  2. lol
    there is also a easy way to do this bhai ji
    just right click on "application" & u get edit menu options ;)

    ReplyDelete
  3. well , when you want to apply new changes for all user available on that machine , you need to follow this method. those who want to build their own custom OS , this is the trick which they use .

    ReplyDelete

:) :-) :)) =)) :( :-( :(( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ :-$ (b) (f) x-) (k) (h) (c) cheer

© 2009 Start With Linux | Mannu Linux
Designed by cyb3r.gladiat0r
Posts RSSComments RSS
Back to top