xdg-desktop-menu command_examples
xdg-desktop-menu – command line tool for (un)installing desktop menu items
The company ShinyThings Inc. has developed an application named “WebMirror” and would like to add it to the application menu. The company will use “shinythings” as its vendor id. In order to add the application to the menu there needs to be a .desktop file with a suitable Categories entry:
shinythings-webmirror.desktop:
———————————————————–
[Desktop Entry]
Encoding=UTF-8
Type=Application
———————————————————–
Exec=webmirror
Icon=webmirror
———————————————————–
Name=WebMirror
Name[nl]=WebSpiegel
———————————————————–
Categories=Network;WebDevelopment;
———————————————————–
Now the xdg-desktop-menu tool can be used to add the shinythings-webmirror.desktop file to the desktop application menu:
xdg-desktop-menu install ./shinythings-webmirror.desktop
Note that for the purpose of this example the menu items are available in two languages, English and Dutch. The language code for Dutch is nl.
In the next example the company ShinyThings Inc. will add its own submenu to the desktop application menu consisting of a “WebMirror” menu item and a “WebMirror Admin Tool” menu item.
First the company needs to create two .desktop files that describe the two menu items. Since the items are to be added to a new submenu it is not necessary to include a Categories= line:
shinythings-webmirror.desktop:
[Desktop Entry]
Encoding=UTF-8
Type=Application
Exec=webmirror
Icon=shinythings-webmirror
———————————————————–
Name=WebMirror
Name[nl]=WebSpiegel
———————————————————–
shinythings-webmirror-admin.desktop:
———————————————————–
[Desktop Entry]
Encoding=UTF-8
Type=Application
———————————————————–
Exec=webmirror-admintool
Icon=shinythings-webmirror-admintool
———————————————————–
Name=WebMirror Admin Tool
Name[nl]=WebSpiegel Administratie Tool
———————————————————–
In addition a .directory file needs to be created to provide a title and icon for the sub-menu itself:
———————————————————–
shinythings-webmirror.directory:
———————————————————–
[Desktop Entry]
Encoding=UTF-8
———————————————————–
Icon=shinythings-webmirror-menu
———————————————————–
Name=WebMirror
Name[nl]=WebSpiegel
———————————————————–
These file can now be installed with:
———————————————————–
xdg-desktop-menu install ./shinythings-webmirror.directory \ ./shinythings-webmirror.desktop ./shinythings-webmirror-admin.desktop
———————————————————–
The menu entries could also be installed one by one:
xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \ ./shinythings-webmirror.desktop xdg-desktop-menu install --noupdate ./shinythings-webmirror.directory \ ./shinythings-webmirror-admin.desktop xdg-desktop-menu forceupdate
———————————————————–
Although the result is the same it is slightly more efficient to install all files at the same time.
———————————————————–
The *.desktop and *.directory files reference icons with the names webmirror, webmirror-admin and webmirror-menu which should also be installed. In this example the icons are installed in two different sizes, once with a size of 22×22 pixels and once with a size of 64×64 pixels:
xdg-icon-resource install --size 22 ./wmicon-22.png shinythings-webmirror xdg-icon-resource install --size 22 ./wmicon-menu-22.png shinythings-webmirror-menu xdg-icon-resource install --size 22 ./wmicon-admin-22.png shinythings-webmirror-admin xdg-icon-resource install --size 64 ./wmicon-64.png shinythings-webmirror xdg-icon-resource install --size 64 ./wmicon-menu-64.png shinythings-webmirror-menu xdg-icon-resource install --size 64 ./wmicon-admin-64.png shinythings-webmirror-admin