How to Integrate Applications and Scripts to a Linux Desktop

Laptop on a blue background with a Linux command prompt.
fatmawati ahmad zaenuri/Shutterstock.com

On Linux, an application without a desktop file cannot be integrated into your desktop environment. Most applications provide one, but occasionally you need to create one. It’s very easy, just follow these steps.

desktop files

Desktop files contain information about the application or script to which they belong. They are most commonly used with executable binaries, but you can also use them with a script if you wish. For brevity, we’ll just say “application”.

A desktop file contains metadata that your desktop environment can reference when dealing with that application. The desktop file specifies where the application’s binary or script resides, what icon it uses, and so on. Because desktop files are stored in standard locations, your desktop environment can reliably find and reference them.

If an application doesn’t have a desktop file, some of its integration into your desktop environment will fail. It doesn’t show up in application search results, nor can you pin it to the Dock or any other launcher. Some desktop environments allow you to place a desktop file on your desktop that acts as a shortcut so you can run the application by double-clicking the desktop file. This use case gave them their name.

Applications may not have a desktop file for a number of reasons. The installer routine may have hiccups, or it may be a minimalist installer that never intended to provide one. When you download an application as source code and compile it on your computer, a desktop file is often not created.

Of course, if you wrote the application yourself, you are also responsible for the desktop file. Applications that behave well and meet the norms and expectations of your desktop environment feel professional and give users confidence that they know what they are doing.

Regardless of why you are creating a desktop file, the procedure is the same in all cases.

The construction of a desktop file

A desktop file is a plain text file. They can be created with any text editor. They are given the same name as the application they represent and, by convention, have a .desktop extension.

Desktop files can contain comments, group headers, and key-value pairs.

  • Comments: Comments start with a hash”#“.
  • group headers: Group headings act as section titles. They are enclosed in brackets “[]“. They are used to group related sets of key-value pairs. The only mandatory group header is “[Desktop Entry].”
  • key-value pairs: Settings are entered by providing values ​​for named items or “keys”. For example, Type=Application is a key-value pair. “Type” is the key and “Application” is the value.

A worked example

Before you begin, make sure the application is running. Open a terminal window and launch the application. When it works, that’s great. You can go ahead and create your desktop file. If the application isn’t running, it still won’t run no matter what you put in your desktop file.

You must fix everything that is preventing the application from launching before you even consider adding another layer of abstraction via a desktop file.

The program we are working with has an executable file called taf located in the /usr/local/bin/taf/ directory. We start the application to make sure that it starts without any problems.

./taf

Start the taf application

The program starts without any problems.

The taf application running as a GNOME GTK application

This simple test provides useful knowledge. If we’re having trouble trying to launch the application from our desktop file, that means the problem must be something with the desktop file and not the application itself.

We can create our desktop file anywhere, but to use it we need to copy it to one of two places.

  • If you are the only person using the application, copy your desktop file to your ~/.local/share/applications directory.
  • If you want all users to be able to use the application, copy your desktop file to the /usr/share/applications/ directory.

A fully functional desktop file does not need to contain a great deal of information. Here is the desktop file we created for the taf Application. It’s called taf.desktop.

[Desktop Entry]
Name=Text Adventure Framework
GenericName=Interpreter for GDL Adventure Scripts
Comment=Game Description Language interpreter
Version=1.0
Exec=/usr/local/bin/taf/taf
Path=/usr/local/bin/taf/
Icon=/usr/local/bin/taf/taf_icon.png
Terminal=false
Type=Application
Categories=GNOME;GTK;Game;

This can be used as a template for your own desktop files. Remember to use the name of your executable for the application you are creating the desktop file for and change the directory paths accordingly.

That means each of the lines.

  • [Desktop Entry]: This line identifies the file as a desktop file. Even if the file was misnamed and didn’t have a “.desktop” extension, it should be recognized and treated as a desktop file.
  • Surname: The full title of the application, not the name of the executable. This will appear under the application icon when viewed in the desktop environment. It is also the text used in tooltips.
  • generic name: A general description of the type of application. If there is a general term that applies, such as B. Web browser, IDE or word processor, you can use this.
  • comment: This is intended to provide additional information to complement the Name and GenericName key-value pairs.
  • execution: The version of the desktop file specification that this file conforms to.
  • version: This can be the name of the executable or the full path to the executable, including the name of the executable.
  • path: This is the path to the directory from which the application will be started. It is the application’s working directory at startup time.
  • symbol: The icon of the application. This icon is used in the application’s search results and when adding the application to the Dock or other launcher.
  • terminal: Indicates whether the application is running in a terminal window.
  • Type: For regular applications, this is always “Application”.
  • categories: This value should be terminated with a semicolon “;” because it holds a list. The list contains categories under which the application can be listed in menus.

Every time you change yours live Desktop file – the ones in “~/.local/share/applications” or “/usr/share/applications/” – you’ll need to log out and back in to see the effects of your changes. To avoid this, you can use the update-desktop-database Command. You must use sudo if you do that.

sudo update-desktop-database

Updating the desktop file database

There is also a utility to check your desktop file for correctness. If it finds any syntax or other errors, they will be reported to you. We add the word “Application” to the “Categories” line in our file and check it.

We changed the last line as follows:

Categories=GNOME;GTK;Game;Application;

This should throw an error as the Application category is deprecated.

desktop-file-validate taf.desktop

Checking a desktop file for errors

The validator warns us that the “Application” category is no longer an acceptable value in the “Categories” list.

Using your desktop file

If the application is only for you, copy the desktop file to your ~/.local/share/applications directory. If all users are allowed to use the application, copy the desktop file to the /usr/share/applications/ directory.

We will copy it to the /usr/share/applications/ directory.

sudo cp taf.desktop /usr/share/applications

Copy the desktop file to the /usr/share/applications directory

We also make sure that our new desktop file is read and its metadata is added to the database.

sudo update-desktop-database

Updating the desktop file database

The “Super” key is usually located between the left “Ctrl” and “Alt” keys. Pressing the “Super” button in GNOME brings up the Application Finder. Since our desktop file describes an application called “Text Adventure Framework”, entering “Text” as a search hint is sufficient to display the application’s icon in the search results.

Clicking the icon launches the application.

Updating the desktop file database

The application has been well integrated into the desktop environment. Its icon is displayed correctly in the dock while running. When you hover over the icon, a tooltip appears with the full name of the application.

Clicking the icon displays the window preview showing the windows that the application has open.

Right-clicking on the application icon opens a context menu. Selecting the Add to Favorites option will pin the application to the dock.

The context menu with the "Pin to favorites" option highlighted

The application icon moves across the divider and becomes a persistent icon in the Dock. The icon is present even when the application is not running.

Go native

Users expect to be able to do certain things with desktop applications. You expect the application to be listed in the search results. You’ll expect it to pin to launchers and docks, and have the other niceties of a well-behaved native application. A surprising number of these interactions are driven by desktop files.

If you’re dealing with an application that’s missing the desktop file, you can now create one for it. It’s probably better to start the application manually each time.

TIED TOGETHER: How to be more productive in Ubuntu with keyboard shortcuts

Leave a Reply

Your email address will not be published. Required fields are marked *