Table of contents
2) Add executable permissions to the test.desktop shortcut
3) Edit test.desktop content and parameters
4) Modify the shortcut property to be executable by double-clicking
5) Send desktop shortcut to desktop
0. Background + environment
ubuntu 16.04
Project requirements, currently there is an executable program (test.sh), the script test.sh executes a certain command to open the application, but it is not good to put .sh on the desktop (the icon is the default), so I hope to make one Desktop shortcut, has its own icon, and can be opened by double-clicking
Originally this icon
After making it is such an icon, it is a .desktop desktop shortcut (executable program)
You need to prepare:
- test.sh executable program (implemented well, this article does not focus on the content of .sh)
- A picture as a shortcut
1. Principle
First of all, we must understand that this name "C10" is essentially a .desktop desktop shortcut, which can be executed by double-clicking. You need to write some relevant parameters inside this file, such as the location to execute the .sh script and the icon you want to use.
The relevant parameters of .desktop are as follows. You can add any parameters you need. In the example below, I only show the more basic parameters (few, but enough to meet most situations)
URL for more information: Desktop Entry Specification (specifications.freedesktop.org)
2. Detailed steps
1) Create a .desktop shortcut
Note: Be sure to create [/usr/share/applications] in this directory
Because this directory is the path for the system to automatically create desktop shortcuts, the save format is xxxx.desktop
(I tried to create it on the desktop, but the picture will not be displayed)
Open the command line, enter the command: enter this path, and then use touch to create a shortcut called test (this name is actually not important, because the name that is written in the parameter will be displayed later)
cd /usr/share/applications
sudo touch test.desktop
2) Add executable permissions to the test.desktop shortcut
sudo chmod +x test.desktop
3) Edit test.desktop content and parameters
Open this file with vim first, if you don’t have vim, you can also use vi
Then copy the content in ( note that the content after the equal sign should be replaced with your own, such as name, executable program location, picture, etc. )
[Desktop Entry]
Type=Application
Name=C10
GenericName=C10
Comment=test
Exec="/home/wangyunuo/test.sh" %f
Icon=/home/wangyunuo/testImg.png
Terminal=true
Categories=X-Application;
Interpretation of parameters
Type | To allow new types to be added in the future, implementations should ignore desktop entries with unknown types. There are three types: Application, Link, and Directory. Because I want to run the application, I use Application in this field |
Name | Application-specific name. My name is "C10" |
GenericName | Generic name of the application |
Comment | The item's tooltip. Right-click the executable program, you can see it in the properties |
Exec | Exec is the path to an executable or script file (.sh). My executable script.sh is in the path of [/home/wangyunuo/test.sh] Note: the value of the Exec field needs to be enclosed in quotation marks and add "%f" |
Icon | The location of the picture, the picture I used is in the path [/home/wangyunuo/testImg.png], just write the path directly after = |
Terminal | Whether the program is running in a terminal window. Usually there is no need to open the terminal, false is not to run in the terminal, true is to run in the terminal. |
Categories | The category in which the entry should appear in the menu. |
Well, after replacing the parameters with your own, you can save and exit
4) Modify the shortcut property to be executable by double-clicking
In the [/usr/share/applications] directory, find the file you just finished writing (note that the name at this time has been replaced with the name after the Name parameter, not the initial test.desktop), right click, and select Properties
In the [Permissions] permission, choose to tick this Execute
At this point, the configuration has been completed in the default path, double-click to try to see if you can execute your .sh program
If it can be executed, we will send it to the desktop, which is more convenient to click
5) Send desktop shortcut to desktop
Right click - select "Copy to" - select the desktop
Then it is sent to the desktop
So far, we have created a desktop shortcut for the executable program test.sh, which can be executed by double-clicking it.
reference:
Writing .desktop files and debugging methods in ubuntu - Programmer Sought
Unbuntu Manually Create Desktop Shortcut Desktop File Detailed Explanation
--END--