Advertisement
Tritonio

Anatomy of a .desktop File

Mar 17th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. One of the beautiful things about Linux is that developers tend to be conscientious about the use of technical standards. Freedesktop.org maintains a wide series of standards for X Window System desktops, which apply to Gnome, KDE, LXDE and XFCE (I’m not sure whether Fluxbox implements these standards.) The standard for “desktop entries” is still technically a draft, but is generally accepted by the larger X community.
  2.  
  3. The .desktop file fills two primary functions: first, it informs the desktop environment how the file is to be handled by the desktop environment with regard to menu placement, display, environmental variables, and similar. In this function, it resides globally in /usr/share/applications/ and for specific users in $HOME/.local/applications. The second function is the direct shortcut on the desktop itself. In this function, it resides in $HOME/Desktop. The same file fills both functions, so if you want to have an application both in the menu and on your desktop, you’ll need to put the .desktop file in two places. Let’s take a closer look, shall we?
  4.  
  5. The .desktop file is generally in a key,value pair format. This means that, generally speaking, each line will look like this:
  6. key=value
  7. Required Elements
  8.  
  9. Type – specifies the type of desktop entry. Currently, there are three valid types: Application, Link and Directory.
  10. Name – The name of the specific application or directory. This determines the actual display name for the menu/desktop entry.
  11. Exec – provides the actual command to execute, with associated arguments (if necessary.)
  12. Optional Elements
  13.  
  14. Version – specifies the version of the Desktop Entry Specification to which the .desktop file conforms (currently 1.0).
  15. Encoding – The encoding for the .desktop file. The standard calls for UTF-8.
  16. GenericName – specifies the generic name of the application.
  17. NoDisplay – This is a boolean (i.e. true/false) element. If set to “true”, it means “this application exists but should not appear in menus.” This is most frequently used to associate an application with MIME types so file managers know how to handle things.
  18. Comment – specifies tooltip entries for the file.
  19. Icon – specifies the icon to be used. This entry supports both icons supported under the FreeDesktop Icon Theme Specification (which I haven’t yet fully grokked) as well as absolute paths.
  20. Hidden – another boolean entry which, if true, essentially treats the application as having been deleted.
  21. OnlyShowIn – If you use multiple desktop environments (say, for instance, you use both Gnome and LXDE) and only want the .desktop entry to apply to a few of the environments, this line specifies the environments in which the entry should apply. This entry is mutually exclusive with NotShowIn.
  22. NotShowIn – As above, but instead of specifying where to display the entry, it displays where NOT to display the entry. This is more useful if you have numerous environments but only want to exclude one or two.
  23. Path – specifies the working directory for an application to run in.
  24. Terminal – a boolean entry which specifies whether or not the application requires a terminal to run.
  25. MimeType – specifies any associated MIME types with this application.
  26. Categories – Categories in which this application should appear in menus. Supported categories vary from system to system, but there is an emerging standard for categories.
  27.  
  28. Finally, any line beginning with an octothorpe (“#”) is considered a comment.
  29. Putting It All Together
  30.  
  31. Now that we have all the elements, we can open up any text editor and create a .desktop entry. Here’s a very simple sample:
  32.  
  33. [Desktop Entry]
  34. Encoding=UTF-8
  35. Version=1.0
  36. Type=Application
  37. Terminal=false
  38. Exec=$HOME/MyApp
  39. Name=My Application
  40. Icon=$HOME/Icons/MyIcon.png
  41.  
  42. Save your entry (as filename.desktop), then put a copy in $HOME/.local/applications and (if you want) another in $HOME/Desktop. If you did it right (and if you’re running Gnome, KDE or LXDE), your new application should show up in your menu and (possibly) on your desktop.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement