Create a custom desktop file to launch a program graphically.
This will work on all Linux distributions.
A working Linux install with a graphical desktop
- # – requires given linux commands to be executed with root privileges either directly as a root user or by use of
- $ – requires given linux commands to be executed as a regular non-privileged user
Have you ever installed a program from an outside source and wished that it had a convenient entry in your desktop environment’s menu? More often than not, Linux applications installed through any channel other than a software repository don’t include a proper desktop entry. Don’t worry, though. They’re actually quite simple to create for yourself.
The entries that you see in your desktop environment’s program menu come from simple plain text configuration files with the
.desktop extension. These files all follow a very basic pattern, and they’re not too long to write in just a few minutes.
Create The File
.desktop entries for your user account are stored at
cd into that directory, and have a look around. You’ll probably see a few files already in there.
Create a new file for your program. Name it something like
program-name.desktop. This guide is going to use the Tor Browser as an example. Feel free to follow along with that. Open your new file in the text editor of your choosing.
On the first line of the file, begin the block for a desktop entry. It should look like this:
Now, you can start adding some basic information to your file. Begin by assigning a name to your program.
Every X window has it’s own class for identification purposes. Give your entry a unique class.
When you mouse over launchers in most desktops, a small dialog box will appear with a short description of the program. Create that entry next.
Comment=Browse With Tor
Most desktops also support generic names for programs. These usually just say what the program is. In this case:
Every desktop file needs a command to execute. Otherwise, what good really is it? The command should really just point to the executable file that you want to run with the launcher and include any options that you want to pass when it’s run. Think of it like you’re running the program from the linux command line. Essentially, that’s what you’re doing every time you click on your launcher.
If you were to copy that command into the terminal and run it, the browser would open. That’s exactly the behavior that you’re looking for.
Launchers aren’t much good without an icon to click. You can use just about any image as an icon, but smaller PNGs with a transparent background work best. Your image can be stored just about anywhere. You only need to include the path to it for your entry.
The Tor Browser comes with an icon buried deep in its directories. That’s the actual path to it.
Type And Catagories
The type and categories values tell any menus where to place your launcher. The type tells the desktop environment if the desktop entry is for an application, link, or directory. The categories value lets it know which categories to place your launcher under.
For a full list of categories that desktop environments recognize, check the offical specification.
MIME types tell the desktop environment which files to associate with the application. These are organized by category, then by extension. You can have as many as you like. Check out VLC. The list is rather long.
If you’re unsure of what to include, take a look at a similar application. This example was copied directly from Firefox.
Keywords aren’t that important. They’re additional metadata that a desktop environment or its utilities can use to search for your entry. They sort of extend the Name and GenericName values, giving you more words to associate with your application.
You are now fully prepared to write your own desktop entries for any application you can think of. These are also a great option for custom scripts and Wine games. Projects downloaded from Github also rarely come with
.desktop files. It’s fairly simple to set one of these up for any one of those scenarios.