MenuConverter.py

Screenshot of a converted directory tree

Purpose

KDE offers the possibility to quickly browse directories using a kind of panel applet. The following script emulates that behaviour for a gnome desktop (2.10) by generating an XDG menu structure for arbitrary directories. Symbolic links are followed, using the link name as the description.

XDG Menu Structure

FreeDesktop.org's standard for XDG menu systems consists of three parts:

.menu files
specify the menu structure and program categories to be shown in each submenu. The system default configuration in /etc/xdg/menus can be replaced by files in ~/.config/menus.
.directory files
are responsible for the translation and appearence of menu entries. Local changes are in ~/.local/share/desktop/directories.
.desktop files
hold information about available programs, local ones are in ~/.local/share/applications.

New programs appear automatically in the submenus with matching categories.

MenuConverter.py

For the entries to appear, you have to prepare the menu system as follows:

Now you are ready to call MenuConverter.py with the path to be converted. An optional -c tries to erase all files that may have been created earlier from the same path (think of it as some primitive uninstall functionality).

When a symbolic link is encountered, the link target is used as the action and the link name as the description for the menu entry. All entries are opened with gnome-open, which should do the Right Thing depending on the referenced file type. You can create a new panel menu with a right click on an entry in the generated submenu. Use gconf-editor (in /apps/panel/objects/.../menu_path) to adjust the menu path if needed. If many entries are generated, a killall gnome-panel may be faster than waiting for it to finish rebuilding the menus from gamin notifications.

Download

MenuConverter.py 0.1. This script was tested on an Ubuntu hoary system with python 2.4. You need the python-xdg module for it to work correctly. It is released under GNU GPL.

References

Desktop Entry Specification 0.9.4. Preston Brown, Jonathan Blandford, Owen Taylor. Freedesktop.org draft specification.

Desktop Menu Specification 1.0.draft-1. Waldo Bastian, Francois Gouget, Alex Graveley, George Lebl, Havoc Pennington, Heinrich Wendel. Freedesktop.org draft specification.