MenuConverter.py
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:
Create a directory ~/.config/menus/local. All generated submenus will be stored here.
Modify or create ~/.config/menus/applications.menu to include a new submenu for the new entries. It has to merge the above created directory, e.g.
<!DOCTYPE Menu PUBLIC '-//freedesktop//DTD Menu 1.0//EN' 'http://www.freedesktop.org/standards/menu-spec/1.0/menu.dtd'> <Menu> <Name>Applications</Name> <MergeFile>/etc/xdg/menus/applications.menu</MergeFile> <Menu> <Name>Local Data</Name> <Directory>local.directory</Directory> <MergeDir>local</MergeDir> </Menu> </Menu>
The current title Local Data is hardcoded in the source code.
Create a directory file for this submenu, e.g. ~/.local/share/desktop-directories/local.directory:
[Desktop Entry] Name=Local Data Comment=User defined entries Icon=hint Type=Directory Encoding=UTF-8
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.