Pages

Saturday, July 26, 2014

How to create desktop file in linux

If we install software in linux (in this case consider Ubuntu) manually, which is without using package management software like "Ubuntu Software Center", we are unable to launch them from the launcher or main menu (we need to launch software from the terminal).

Let's see how we can list our application on the menu ......

To add applications to the menu we have to create a desktop file which is a text file with ".desktop" extension with a unique name which contain meta-data about the application.

Before creating a desktop file, we'll see how applications installed via Ubuntu Software Center appeared in main menu.

If I install "myPaint" application using software center, the desktop file is look like this:



Let's see how we can create a desktop file.

The primary functions of desktop file is to inform desktop environment, how to handle file such as menu placement, and how to display.

Format of .desktop file

The desktop file consists set of key-value pairs.

[Desktop Entry] Header to recognize key value pairs associated with desktop
Type [required] Type of desktop entry
Encoding [optional] Encoding of the entries in the file
Name [required] Name of the application / directory. This is the display name in the menu or launcher
GenericName [optional] Can used to state the generic name of the application.
eg.: "Text Editor" for "GEdit"
Comment Comment which can be used as a tooltip. Can include any useful information
Exec [required] The actual command to execute the target application from a shell. We also can add additional arguments if needed.
Icon [optional] Icon to be used
Terminal [optional] Boolean entry to specify whether the application requires terminal to execute

There are more optional entries refer Recognized desktop entry keys

Now let's test .......

 here are steps to follow to add eclipse IDE to the main menu in Ubuntu

  • Extract eclipse distribution to the target installation directory.
  • Create the desktop file
       Create the desktop file at:
           /usr/share/applications/ directory if it is globally available application
          ~/.local/share/applications if only for specific user 

[Desktop Entry]
  Version=1.0
  Name=Eclipse

  Exec=eclipse
  Terminal=false
  Icon=/opt/eclipse/icon.xpm
  Type=Application
  Categories=IDE;Development
  X-Ayatana-Desktop-Shortcuts=NewWindow

  [NewWindow Shortcut Group]
  Name=New Window
  Exec=eclipse
  TargetEnvironment=Unity
  • Restart the PC or logout  

Now the you can invoke eclipse from main menu....

Cheers ..



No comments:

Post a Comment