ObjectiveCreate a custom desktop file to launch a program graphically.
DistributionsThis will work on all Linux distributions.
RequirementsA 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
IntroductionHave 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
.desktopextension. These files all follow a very basic pattern, and they're not too long to write in just a few minutes.
Create The FileThe
.desktopentries for your user account are stored at
cdinto 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:
Basic InfoNow, you can start adding some basic information to your file. Begin by assigning a name to your program.
Name=Tor BrowserEvery X window has it's own class for identification purposes. Give your entry a unique class.
StartupWMClass=Tor BrowserWhen 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 TorMost desktops also support generic names for programs. These usually just say what the program is. In this case:
ExecutionEvery 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.
Exec=/home/user/tor-browser_en-US/Browser/start-tor-browserIf 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.
IconsLaunchers 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.
Icon=/home/user/tor-browser_en-US/Browser/browser/icons/mozicon128.pngThe Tor Browser comes with an icon buried deep in its directories. That's the actual path to it.
Type And CatagoriesThe 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 TypesMIME 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.
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml; application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;If you're unsure of what to include, take a look at a similar application. This example was copied directly from Firefox.
KeywordsKeywords 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.
Closing ThoughtsYou 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
.desktopfiles. It's fairly simple to set one of these up for any one of those scenarios.