How to create desktop launchers on Linux
Desktop launchers are handy shortcuts that allow you to run applications or scripts from your desktop, without opening a terminal or browsing through menus. They are especially useful for customizing your Linux experience and making it more convenient and efficient.
In this blog post, I will show you how to create desktop launchers on Linux, focusing on the GNOME desktop environment.
What is a desktop launcher?
A desktop launcher is a file that contains information about an application or a script, such as its name, icon, command, description, and categories. It usually has the extension .desktop
and follows a standard format defined by the Desktop Entry Specification. Here is an example of a desktop launcher for Firefox:
[Desktop Entry]
Name=Firefox
Comment=Browse the Web
Exec=firefox %u
Icon=firefox
Terminal=false
Type=Application
Categories=Network;WebBrowser;
The desktop launcher file has two main sections: [Desktop Entry]
and [Desktop Action]
. The first section contains the basic information about the application or the script, such as:
Name
: The name that will be displayed on the desktop or in the menu.Comment
: A brief description of the application or the script.Exec
: The command that will be executed when the launcher is clicked. It can include arguments, such as%u
for URLs or%f
for files.Icon
: The icon that will be displayed on the desktop or in the menu. It can be a path to an image file or a name of an icon from the current icon theme.Terminal
: A boolean value that indicates whether the application or the script should run in a terminal or not.Type
: The type of the launcher, which can beApplication
,Link
, orDirectory
.Categories
: A list of categories that the application or the script belongs to, separated by semicolons. These categories are used to organize the launchers in the menu.
The second section, [Desktop Action]
, is optional and allows you to define additional actions that can be performed by the launcher, such as opening a new window, a private window, or a specific profile. Each action has a unique identifier and a set of properties, such as:
Name
: The name of the action that will be displayed in the context menu of the launcher.Exec
: The command that will be executed when the action is selected.Icon
: The icon that will be displayed in the context menu of the launcher.
Here is an example of a desktop launcher for Firefox with two additional actions:
[Desktop Entry]
Name=Firefox
Comment=Browse the Web
Exec=firefox %u
Icon=firefox
Terminal=false
Type=Application
Categories=Network;WebBrowser;
Actions=NewWindow;NewPrivateWindow;
[Desktop Action NewWindow]
Name=Open a New Window
Exec=firefox --new-window %u
Icon=firefox
[Desktop Action NewPrivateWindow]
Name=Open a New Private Window
Exec=firefox --private-window %u
Icon=firefox
How to create a desktop launcher?
To create a desktop launcher, you need to create a .desktop
file with the information and the actions that you want. You can use any text editor of your choice, such as Gedit, Nano, or Vim. You can also use a graphical tool, such as GNOME Desktop Item Edit, which provides a user-friendly interface for creating and editing desktop launchers.
Once you have created the .desktop
file, you need to save it in a specific location, depending on where you want the launcher to appear. There are two main locations for desktop launchers:
~/.local/share/applications
: This location is for user-specific launchers, which will only appear for the current user. You can create a folder with your username and place your launchers there, or you can use the root folder directly./usr/share/applications
: This location is for system-wide launchers, which will appear for all users. You need root privileges to create or edit launchers in this location, so you need to usesudo
or a graphical tool that supports authentication, such as GNOME Software.
After saving the .desktop
file in the appropriate location, you need to make it executable, so that it can be run by the system. You can do this by using the chmod
command in the terminal, or by right-clicking on the file and selecting Properties > Permissions > Allow executing file as program
.
Alternatively, make it executable via terminal:
chmod +x /usr/share/applications/your-app.desktop
Finally, you need to refresh the desktop or the menu, so that the launcher can be recognized and displayed. You can do this by logging out and logging back in, or by using a command such as killall gnome-shell
or xdg-desktop-menu forceupdate
.
How to customize a desktop launcher?
You can customize a desktop launcher by editing the .desktop
file and changing the properties and the actions that you want. You can also change the icon of the launcher by replacing the Icon
property with a different image file or icon name. You can find icons in the /usr/share/icons
or ~/.local/share/icons
folders, or you can download icons from online sources, such as GNOME Look.
You can also create custom icons by using an image editor, such as GIMP, or a vector graphics editor, such as Inkscape. You can save the icon as a PNG or SVG file, and place it in the same folder as the .desktop
file, or in the ~/.local/share/icons
folder. You can then use the file name or the icon name in the Icon
property of the .desktop
file.
Other cool ways to use desktop shortcuts
How to create a desktop launcher for a script
You can create a desktop launcher for a script by using the same format as for an application, but changing the Exec
property to point to the script file, and adding the shebang
line (#!/bin/bash
or #!/usr/bin/env python
, etc.) at the beginning of the script. You also need to make the script executable, by using the chmod
command or the file properties. Here is an example of a desktop launcher for a script that displays a message:
[Desktop Entry]
Name=Hello
Comment=Display a message
Exec=/home/user/hello.sh
Icon=dialog-information
Terminal=false
Type=Application
Categories=Utility;
And here is the script file (hello.sh
):
#!/bin/bash
zenity --info --text="Hello, world!"
How to create a desktop launcher for a website
You can create a desktop launcher for a website by using the Link
type instead of the Application
type, and adding the URL
property with the website address. You can also specify the browser that you want to use to open the website, by using the Exec
property with the browser command and the %u
argument. Here is an example of a desktop launcher for a website:
[Desktop Entry]
Name=Bing
Comment=Search the Web
URL=https://www.bing.com
Icon=bing
Terminal=false
Type=Link
Categories=Network;WebBrowser;
Exec=firefox %u
How to create a desktop launcher for a folder
You can create a desktop launcher for a folder by using the Directory
type instead of the Application
type, and adding the Path
property with the folder path. You can also specify the file manager that you want to use to open the folder, by using the Exec
property with the file manager command and the %f
argument. Here is an example of a desktop launcher for a folder:
[Desktop Entry]
Name=Documents
Comment=Open the Documents folder
Path=/home/user/Documents
Icon=folder-documents
Terminal=false
Type=Directory
Categories=Utility;FileManager;
Exec=nautilus %f
Conclusion
In this blog post, I have shown you how to create desktop launchers on Linux, focusing on the GNOME desktop environment. Desktop launchers are useful for running applications or scripts from your desktop, without opening a terminal or browsing through menus. They are also easy to create and customize, by using a text editor or a graphical tool, and by following a standard format. I hope you have found this blog post helpful and informative, and that you have enjoyed creating your own desktop launchers. Thank you for reading! 😊