I have an application that I start only from the command line. How can I add the command (and preferably a nice logo) to Gnome's application menu?
-
If you right click do you get an "Edit Menu" item?slm– slm ♦2013-11-30 18:42:15 +00:00Commented Nov 30, 2013 at 18:42
-
no, no right click menu at all.mart– mart2013-11-30 19:46:05 +00:00Commented Nov 30, 2013 at 19:46
-
See askubuntu.com/questions/792067/…Cees Timmerman– Cees Timmerman2019-12-20 11:57:44 +00:00Commented Dec 20, 2019 at 11:57
5 Answers
In GNOME and other freedesktop.org-compliant desktop environments, such as KDE and Unity, applications are added to the desktop's menus or desktop shell via desktop entries, defined in text files with the .desktop extension (referred to as desktop files). The desktop environments construct menus for a user from the combined information extracted from available desktop entries.
Desktop files may be created in either of two places:
/usr/share/applications/for desktop entries available to every user in the system~/.local/share/applications/for desktop entries available to a single user
You might need to restart GNOME for the new added applications to work.
Per convention, desktop files should not include spaces or international characters in their name.
Each desktop file is split into groups, each starting with the group header in square brackets ([]). Each section contains a number of key, value pairs, separated by an equal sign (=).
Below is a sample of desktop file:
[Desktop Entry]
Type=Application
Encoding=UTF-8
Name=Application Name
Comment=Application description
Icon=/path/to/icon.xpm
Exec=/path/to/application/executable
Terminal=false
Categories=Tags;Describing;Application
Explanation
[Desktop Entry]theDesktop Entrygroup header identifies the file as a desktop entryTypethe type of the entry, valid values areApplication,LinkandDirectoryEncodingthe character encoding of the desktop fileNamethe application name visible in menus or launchersCommenta description of the application used in tooltipsIconthe icon shown for the application in menus or launchersExecthe command that is used to start the application from a shell.Terminalwhether the application should be run in a terminal, valid values aretrueorfalseCategoriessemi-colon (;) separated list of menu categories in which the entry should be shown
Command line arguments in the Exec key can be signified with the following variables:
%fa single filename.%Fmultiple filenames.%ua single URL.%Umultiple URLs.%da single directory. Used in conjunction with%fto locate a file.%Dmultiple directories. Used in conjunction with%Fto locate files.%na single filename without a path.%Nmultiple filenames without paths.%ka URI or local filename of the location of the desktop file.%vthe name of the Device entry.
Note that ~ or environmental variables like $HOME are not expanded within desktop files, so any executables referenced must either be in the $PATH or referenced via their absolute path.
A full Desktop Entry Specification is available at the Freedesktop.org Specification Repository.
Launch Scripts
If the application to be launched requires certain steps to be done prior to be invoked, you can create a shell script which launches the application, and point the desktop entry to the shell script. Suppose that an application requires to be run from a certain current working directory. Create a launch script in a suitable to location (~/bin/ for instance). The script might look something like the following:
#!/bin/bash
pushd "/path/to/application/directory"
./application "$@"
popd
Set the executable bit for the script:
$ chmod +x ~/bin/launch-application
Then point the Exec key in the desktop entry to the launch script:
Exec=/home/user/bin/launch-application
-
I did that, I can see the icon under applications, but when I click the app does not start, the cursor only changes to a loading symbol for a few seconds. No error message.mart– mart2013-12-01 08:49:50 +00:00Commented Dec 1, 2013 at 8:49
-
@mart Can you tell us which application you are trying to add a launcher for?Thomas Nyman– Thomas Nyman2013-12-01 11:21:24 +00:00Commented Dec 1, 2013 at 11:21
-
1FTL - an indie game I bought somewhere on the web. Starting from Console works.mart– mart2013-12-01 15:12:37 +00:00Commented Dec 1, 2013 at 15:12
-
2@mart
<path>/.FTLwould point to a hidden file called.FTL, which is not the same as./FTL, which points to a file calledFTLin the current directory. You can try to launchFTLvia/full/path/path/to/FTLin a terminal to see if you get any meaningfull error output. For instance, if the executable searches for libraries in the current working directory, you might have to do a launcher script which does something along the lines ofpushd <path>; ./FTL; popdand point theExecspecifier in the desktop file to the launcher script instead.Thomas Nyman– Thomas Nyman2013-12-01 16:35:39 +00:00Commented Dec 1, 2013 at 16:35 -
1correction: it works from inside the directorymart– mart2013-12-01 20:36:10 +00:00Commented Dec 1, 2013 at 20:36
Very good answer from Thomas Nyman.
Gnome comes with gui tool gnome-desktop-item-edit assisting in creating *.desktop files.
We need to use it from command line, or create a desktop file for it.
Instructions to make Gnome Application from gnome-desktop-item-edit
Open terminal windows and type the following command:
gnome-desktop-item-edit --create-new /home/[your user name]/.local/share/applicationsIn the opened window fill the following:
Name: Gnome Applicaiton
Command: gnome-desktop-item-edit --create-new /home/[your user name]/.local/share/applications
Click on the icon to select a different icon.
Click OK to close the windows
Close the terminal window
Testing newly generated Gnome Application
- Open dash
- Type Application
- You should see the
Gnome Applicationentered before - Select it
- Create another application
To create for all users use:
sudo gnome-desktop-item-edit --create-new /usr/share/applications
If the command is missing on debian/ubuntu try:
sudo apt-get install gnome-panel
-
2This works really well, thanks. Is there any way to alter which menu the new application appears in ? Mine appeared in Applications->OtherSteveP– SteveP2019-07-22 12:37:26 +00:00Commented Jul 22, 2019 at 12:37
-
4That command is unavailable in Ubuntu 19.10.Cees Timmerman– Cees Timmerman2019-12-17 16:06:22 +00:00Commented Dec 17, 2019 at 16:06
-
3This command is also unavailable in CentOS 8, has it been deprecated? Or is there a way to somehow install this package?hpy– hpy2020-04-30 21:27:32 +00:00Commented Apr 30, 2020 at 21:27
-
3It seems the command is removed (since 3.32?) askubuntu.com/q/1184733 gitlab.gnome.org/GNOME/gnome-panel/commit/…hashlash– hashlash2020-12-02 03:20:30 +00:00Commented Dec 2, 2020 at 3:20
-
Is there any alternative after @hashlash's finding? There's neither a
gnome-desktop-item-editnor agnome-paneltosudo yum installon RHEL 4.18.Gerold Broser– Gerold Broser2021-08-06 15:12:41 +00:00Commented Aug 6, 2021 at 15:12
A graphical solution is to install MenuLibre
It is available for Ubuntu-flavored distributions via
apt install menulibre
or you can install it from source
It allows to categorize apps per Gnome categories and plays well with Chrome apps.
-
This should be the best answerhungson175– hungson1752023-01-04 02:47:11 +00:00Commented Jan 4, 2023 at 2:47
-
by far much simpler than the most upvoted answersEmilien– Emilien2024-07-12 08:57:22 +00:00Commented Jul 12, 2024 at 8:57
The previous answers from Thomas Nyman and Dudi Boy are very good and detailed. I am posting this because I didn't found a answer for my doubt in any other posts and I had to search in git issues.
After I followed the steps like Thomas Nyman suggested I have been able to make the icon for my program to appear in the App Menu. The problem here is that I use Dash to Dock as side bar and I could not pin the icon as a favourite like other icons. After searching I found that you need to add the line StartupWMClass=ApplicationName in .desktop file.
After that the option to add to favourites will appear by right clicking on the icon in Dash to Dock.
In my case for AndroidStudio.
Stay on the location ~
vi .local/share/applications/androidstudio.desktop
Then add the configuration
[Desktop Entry]
Version=2022.3.1 Patch 2
Name=Android Studio
Comment=Android Studio for linux
Type=Application
Icon=/home/mariot/Downloads/android-studio-2022.3.1.20-linux/android-studio/bin/studio.png
Exec=sh /home/mariot/Downloads/android-studio-2022.3.1.20-linux/android-studio/bin/studio.sh
Terminal=false
Categories=Utility;
Set grants with the command:
gio set .local/share/applications/androidstudio.desktop "metadata::trusted" yes
Then if all the paths are corrects you could test with:
gio launch .local/share/applications/androidstudio.desktop
You could launch the application since the search launcher.
Greetings.

