Question

How can I, in Java or using some other programming language, add a new program group in the applications menu in both KDE and Gnome?

I am testing with Ubuntu and Kubuntu 8. Putting a simple .menu file in ~/.config/menus/applications-merged worked in Kubuntu, but the same procedure does nothing in Ubuntu.

The content of my file is as follows:

<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" "http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd">
<Menu>
<Menu>
  <Name>My Program Group</Name>
  <Include>
   <Filename>shortcut.desktop</Filename>
  </Include>
</Menu>
</Menu>

Note that the .desktop file is correctly placed in ~/.local/share/applications.

Ps: The original question did not specify I wanted a solution in a programmatic way.

Was it helpful?

Solution

Maybe xdg-desktop-menu does that? See man xdg-desktop-menu or http://manpages.ubuntu.com/manpages/hardy/en/man1/xdg-desktop-menu.html .

OTHER TIPS

Thanks, oliver. I used xdg-desktop-menu and then analyzed its output. The correct menu file needs to explicitly name the outer menu (Applications), as follows:

<!DOCTYPE Menu PUBLIC "-//freedesktop//DTD Menu 1.0//EN" 
    "http://www.freedesktop.org/standards/menu-spec/menu-1.0.dtd">
<Menu>
    <Name>Applications</Name>
<Menu>
    <Name>My Program Group</Name>
    <Include>
        <Filename>shortcut.desktop</Filename>
    </Include>
</Menu>
</Menu>

This worked fine in Kubuntu, Ubuntu and Fedora Core 9. Couldn't make it work on openSUSE, though.

I recommend you look into freedesktop.org standards that cover this. Up to date list is available here:

http://www.freedesktop.org/wiki/Specifications/menu-spec

The latest one is currently 1.0:

http://standards.freedesktop.org/menu-spec/1.0/

FreeDesktop.org standards are followed by Gnome, KDE and XFCE, so it should work on any distribution.

In Gnome use System -> Settings -> Menu then just choose New Menu or New Entry.

Not sure what you meant exactly with "in openSUSE the .directory file is mandatory or else the program group does not shows up"; generally I suppose you have to call xdg-desktop-menu twice (once for the program group and once for the program itself), and so you have to supply two different .directory files as well. If the program group is empty, it makes sense that the desktop hides it.

(But maybe I completely misunderstood you here :-) and I've never used xdg-desktop-menu myself anyway).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top