Create a Linux Desktop Launch Icon

Advertisement

Advertisement

Introduction

If you have a script or application you want to run but don't have a desktop or dock launch icon for it, you can create a custom one yourself.

This will work in Gnome, KDE, and other desktops that follow the specifications at freedesktop.org.

For more options, you can read more about Desktop Entry Specifications.

Desktop entry location

There are a few primary places you should consider putting your desktop entry, depending on whether you want it available to everyone or just one user.

These include:

  • /usr/share/applications/
  • /usr/local/share/applications/
  • $HOME/.local/share/applications/

Desktop entry file

The desktop entry file is a simple text file. The file should end with .desktop. For example, myapp.desktop.

Here is an example template:

[Desktop Entry]

# Application, Links (URL), or Directory (sub-group for applications)
Type=Application

Encoding=UTF-8
Icon=/path/to/launch_icon.png
Name=MySpecificApp
GenericName=SomethingGeneric
Comment=This is a tooltip
Exec=/thing/to/execute
# To pass arguments use %u or %U
# Exec=/thing/to/execute %u

# Should run in a terminal?
Terminal=false

# Name of the window. Optional. See below.
# Allows windows to stack
# If this does not match, duplicate icons may show up in your dock
StartupWMClass=name-of-app-window

# Optional categories
Categories=Development;Education;

# If you want to have a special protocol handler. For example,
# this is what Zoom meetings does to register zoommtg:// scheme
# and to be associated with the x-zoom mime type
# MimeType=x-scheme-handler/zoommtg;application/x-zoom;
# X-KDE-Protocols=zoommtg


# Optional actions (right click options)
Actions=launch1;launch2;launch3

[Desktop Action launch1]
Name=Launch normally
Exec=/path/to/launch

[Desktop Action launch2]
Name=Launch with alt options
Exec=/path/to/launch --alts

[Desktop Action launch3]
Name=Launch with alt options again
Exec=/path/to/launch --otheralts

Get the name of a window

If you have issues with the windows not stacking on the launch icon in your dock or favorites bar, you might need to set the StartupWMClass value.

To get a window's name, first run the app so it is visible, then open a terminal and run xprop WM_CLASS. It will then wait until you click on the title bar of a window and then it will print the name of the window. For example:

xprop WM_CLASS

# Then click on the window.

# It will output something like:
# WM_CLASS(STRING) = "code-oss-dev", "code-oss-dev"

# Your entry would have the line:
# StartupWMClass=code-oss-dev

Conclusion

You should now have the ability the create your own desktop launch icon for a Linux desktop. You should also have the resources to learn more about freedesktop.org standards.

Advertisement

Advertisement