19

I have a shell script (studio.sh that launches Android Studio) and a png icon.

How do I use these to create a new application launcher icon for Ubuntu 22.04 such that it will show up in "Show applications" menu, and searches in the "Activities" search bar.

Thanks!

Scorb
  • 1,330

2 Answers2

28
  1. Create a text file with a .desktop extension in your ~/.local/share/applications directory, for example ~/.local/share/applications/studio.desktop

  2. Include at least the following lines, which tell the desktop how to launch the application.

     [Desktop Entry]
     Name=Android Studio
     Exec=studio.sh
     Type=Application
     Icon=studio
    
    • This assumes that the executable, studio.sh, exists somewhere in your search path, e.g. in ~/.local/bin or in ./bin. Else, provide the full pathname to the executable script, e.g. Exec=/home/user/path/to/studio.sh.
    • This assumes that the icon is called studio.png and that the icon is in a standard place, e.g. ~/.local/share/studio.png. Else, provide the full pathname to the icon file, e.g. Icon=/home/user/path/to/studio.png.
    • If the script does not launch a graphical application, but instead should run in a terminal emulator, include a line Terminal=true.

A valid .desktop file in a valid location, with a valid command on the exec= line will automatically, within seconds, appear in your menu system and be searchable.

More fields are available. Study some files under /usr/share/applications to see how it works.

vanadium
  • 97,564
1

One small detail I would like to add here, is if your application opens in a new window instead of the application you created.

Add a StartupWMClass class entry, which can help some desktop environment to properly group the application window:

First, use xprop to find the window class name:

xprop | grep WM_CLASS

Then, click on your application window to see its WM_CLASS value and adjust StartupWMClass accordingly

[Desktop Entry]
Name=Android Studio
Exec=studio.sh
Type=Application
Icon=studio
StartupWMClass=studio-Startstudio