Skip to content

Instantly share code, notes, and snippets.

@sumantro93
Created August 17, 2023 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumantro93/fadee70ae8706f8b348acf254b084749 to your computer and use it in GitHub Desktop.
Save sumantro93/fadee70ae8706f8b348acf254b084749 to your computer and use it in GitHub Desktop.
.destop_file_create
Creating a .desktop file involves creating a plain text file with a specific format and saving it with a .desktop extension. These files are used in Linux and other Unix-like systems to define how a particular program is to be launched, how it appears in menus, etc. Here's how you can create a simple .desktop file:
Open a Text Editor:
Open your favorite text editor; this could be gedit, nano, vi, etc. You can usually open a text editor from your applications menu or from the terminal.
gedit or nano
Enter the Desktop File Content:
In the text editor, you need to enter the content for the .desktop file. Below is a simple example:
[Desktop Entry]
Type=Application
Name=Sample Application Name
Exec=/path/to/application
Icon=/path/to/icon
Comment=This is a sample application
Terminal=false
Categories=Utility;Application;
Here is a description of some commonly used fields:
[Desktop Entry]: The file must start with this line.
Type: The type of the launcher, usually Application.
Name: The name that should be displayed on the menu.
Exec: The command that launches the application.
Icon: The path to the icon file that will be used for this application.
Comment: A short description of the application.
Terminal: Whether the application should run in a terminal window (true or false).
Categories: Specifies the category or categories of the application.
Save the File:
Save the file with a .desktop extension. For example, you might save it as MyApplication.desktop.
Make the File Executable (Optional, but usually required):
After saving the file, you often need to mark it as executable. This can be done from the terminal with the following command:
chmod +x /path/to/MyApplication.desktop
Test the File:
Now you can test your new .desktop file by double-clicking it, or by running it from the terminal with a command like this:
gtk-launch MyApplication
Install the Desktop File (Optional):
To make the application appear in your application menu, you can move the .desktop file to either /usr/share/applications (for all users) or ~/.local/share/applications (for the current user only). You might need administrative rights to move the file to /usr/share/applications.
sudo mv /path/to/MyApplication.desktop /usr/share/applications/
Validate the File (Optional):
As per the test case, after you create the .desktop file, you should validate it using the desktop-file-validate tool as shown:
desktop-file-validate /path/to/MyApplication.desktop
This is a basic .desktop file. There are many other options that you can include to further customize how your application behaves.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment