参考:https://blog.csdn.net/ken2232/article/details/130413147
一、麒麟系统下创建桌面启动器三种方式:
1. 直接拷贝法
/usr/share/applications/ # 在此目录下,体现在左下角的开始菜单中。
/home/userName/Desktop #在此目录下,体现在具体用户userName(如:用户 Abc)的桌面上。
对于已经存在于开始菜单中的直接到 /usr/share/applications/ 目录下,拷贝对应的 .desktop 文件,放在自己的桌面目录下 /home/userName/Desktop,即可显示再桌面上。
2. 自建 .desktop 文件
并不是所有的可执行文件,都有对应的 .desktop 文件。因此,需要自建。
3. 典型的 .desktop 文件,由 linuxdeployqt 工具默认生成的:
[Desktop Entry]
Type=Application
Name=My Test #应用的名字(快捷方式显示的文字)
Exec=/opt/Test/Test #应用的执行路径(绝对路径)
Icon=/opt/Test/Test.png #应用的图标(绝对路径)
Comment=This is my test #说明信息
Terminal=true #是否允许在终端启动
二、自建桌面启动器:
x.desktop文件语法解释:
关键词 意义
[Desktop Entry] 文件头
Encoding 编码
Name 应用名称
Name[xx] 不同语言的应用名称
GenericName 描述
Comment 注释
Exec 执行的命令
Icon 图标路径
Terminal 是否使用终端
Type 启动器类型
Categories 应用的类型(内容相关)
x.desktop文件的内容对应项目说明:
[Desktop Entry]
# 编码
Encoding=UTF-8
# 版本(非必须)
Version=0.8.9
# 类型
Type=Application# 名称,在桌面上显示的名字。 快捷方式的名字
Name=Android Studio
# 注释
Comment=Android Studio IDE
# 通用名(描述)
GenericName=Android Studio
# 执行命令,可执行程序的路径
Exec=/opt/android-studio/bin/studio.sh %f #启动程序。%f会出现在默认打开方式列表
# 图标位置,支持常见图片格式
Icon=/opt/android-studio/bin/studio.png# 这个很关键,当前表明这个快捷方式不是从终端打开。是否允许终端打开,一般为false
Terminal=false# 当 Type 为应用时,表示工作空间路径
Path=
# 分类
Categories=Development;
# 此参数请参考其他文章,我暂时没能理解:)
StartupNotify=true
创建启动器(.Desktop文件)
有些软件提供的启动方式为 .sh 文件,每次启动都需要在终端运行命令。不是很方便,通过查找资料了解到可以创建一个启动器来解决问题。
在linux中,一切皆文件。 启动器就是一个后缀为 .desktop
文件。
我创建的 intelliJ idea 的启动器,文件内容如下
[Desktop Entry]
Encoding=UTF-8
Name=IntelliJ IDEA
GenericName=IntelliJ IDEA
Comment=The Java IDE for Professional Developers by JetBrains
Exec=/opt/SoftWare/idea-IU-172.4343.14/bin/idea.sh %f
Icon=/opt/SoftWare/idea-IU-172.4343.14/bin/idea.png
Terminal=false
Type=Application
Categories=Application;Programme;
使用流程:
创建文件,以.desktop为后缀。
编写内容,修改权限
双击启动程序,添加信任
移动到/usr/share/applications/目录下,这样就可以在左上角应用程序中显示
说明:
其中 Exec 常用的参数有:%f %F %u %U
%f:单个文件名,即使选择了多个文件。如果已选择的文件不在本地文件系统中(比如说在HTTP或者FTP上),这个文件将被作为一个临时文件复制到本地,%f将指向本地临时文件;
%F:文件列表。用于程序可以同时打开多个本地文件。每个文件以分割段的方式传递给执行程序。
%u:单个URL。本地文件以文件URL或文件路径的方式传递。
%U:URL列表。每个URL以分割段的方式传递给执行程序。本地文件以文件URL或文件路径的方式传递。
————————————————
版权声明:本文为CSDN博主「为何不能下定决心?」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Future_promise/article/details/78215201
Table 2. Standard Keys
Key | Description | Value Type | REQ? | Type |
---|---|---|---|---|
Type |
This specification defines 3 types of desktop entries: Application (type 1), Link (type 2) and Directory (type 3). To allow the addition of new types in the future, implementations should ignore desktop entries with an unknown type. |
string | YES | |
Version |
Version of the Desktop Entry Specification that the desktop entry conforms with. Entries that confirm with this version of the specification should use 1.5 . Note that the version field is not required to be present. |
string | NO | 1-3 |
Name |
Specific name of the application, for example "Mozilla". | localestring | YES | 1-3 |
GenericName |
Generic name of the application, for example "Web Browser". | localestring | NO | 1-3 |
NoDisplay |
NoDisplay means "this application exists, but don't display it in the menus". This can be useful to e.g. associate this application with MIME types, so that it gets launched from a file manager (or other apps), without having a menu entry for it (there are tons of good reasons for this, including e.g. the netscape -remote , or kfmclient openURL kind of stuff). |
boolean | NO | 1-3 |
Comment |
Tooltip for the entry, for example "View sites on the Internet". The value should not be redundant with the values of Name and GenericName . |
localestring | NO | 1-3 |
Icon |
Icon to display in file manager, menus, etc. If the name is an absolute path, the given file will be used. If the name is not an absolute path, the algorithm described in the Icon Theme Specification will be used to locate the icon. | iconstring | NO | 1-3 |
Hidden |
Hidden should have been called Deleted . It means the user deleted (at their level) something that was present (at an upper level, e.g. in the system dirs). It's strictly equivalent to the .desktop file not existing at all, as far as that user is concerned. This can also be used to "uninstall" existing files (e.g. due to a renaming) - by letting make install install a file with Hidden=true in it. |
boolean | NO | 1-3 |
OnlyShowIn , NotShowIn |
A list of strings identifying the desktop environments that should display/not display a given desktop entry. By default, a desktop file should be shown, unless an OnlyShowIn key is present, in which case, the default is for the file not to be shown. If
The same desktop name may not appear in both |
string(s) | NO | 1-3 |
DBusActivatable |
A boolean value specifying if D-Bus activation is supported for this application. If this key is missing, the default value is false . If the value is true then implementations should ignore the Exec key and send a D-Bus message to launch the application. See D-Bus Activation for more information on how this works. Applications should still include Exec= lines in their desktop files for compatibility with implementations that do not understand the DBusActivatable key. |
boolean | NO | |
TryExec |
Path to an executable file on disk used to determine if the program is actually installed. If the path is not an absolute path, the file is looked up in the $PATH environment variable. If the file is not present or if it is not executable, the entry may be ignored (not be used in menus, for example). | string | NO | 1 |
Exec |
Program to execute, possibly with arguments. See the Exec key for details on how this key works. The Exec key is required if DBusActivatable is not set to true . Even if DBusActivatable is true , Exec should be specified for compatibility with implementations that do not understand DBusActivatable . |
string | NO | 1 |
Path |
If entry is of type Application , the working directory to run the program in. |
string | NO | 1 |
Terminal |
Whether the program runs in a terminal window. | boolean | NO | 1 |
Actions |
Identifiers for application actions. This can be used to tell the application to make a specific action, different from the default behavior. The Application actions section describes how actions work. | string(s) | NO | 1 |
MimeType |
The MIME type(s) supported by this application. | string(s) | NO | 1 |
Categories |
Categories in which the entry should be shown in a menu (for possible values see the Desktop Menu Specification). | string(s) | NO | 1 |
Implements |
A list of interfaces that this application implements. By default, a desktop file implements no interfaces. See Interfaces for more information on how this works. | string(s) | NO | |
Keywords |
A list of strings which may be used in addition to other metadata to describe this entry. This can be useful e.g. to facilitate searching through entries. The values are not meant for display, and should not be redundant with the values of Name or GenericName . |
localestring(s) | NO | 1 |
StartupNotify |
If true, it is KNOWN that the application will send a "remove" message when started with the DESKTOP_STARTUP_ID environment variable set. If false, it is KNOWN that the application does not work with startup notification at all (does not shown any window, breaks even when using StartupWMClass, etc.). If absent, a reasonable handling is up to implementations (assuming false, using StartupWMClass, etc.). (See the Startup Notification Protocol Specification for more details). | boolean | NO | 1 |
StartupWMClass |
If specified, it is known that the application will map at least one window with the given string as its WM class or WM name hint (see the Startup Notification Protocol Specification for more details). | string | NO | 1 |
URL |
If entry is Link type, the URL to access. | string | YES | 2 |
PrefersNonDefaultGPU |
If true, the application prefers to be run on a more powerful discrete GPU if available, which we describe as “a GPU other than the default one” in this spec to avoid the need to define what a discrete GPU is and in which cases it might be considered more powerful than the default GPU. This key is only a hint and support might not be present depending on the implementation. | boolean | NO | 1 |
SingleMainWindow |
If true, the application has a single main window, and does not support having an additional one opened. This key is used to signal to the implementation to avoid offering a UI to launch another window of the app. This key is only a hint and support might not be present depending on the implementation. | boolean | NO | 1 |
例子
在此目录下的例子:
/usr/share/applications/
# python3.9.desktop
[Desktop Entry]
Name=Python (v3.9)
Comment=Python Interpreter (v3.9)
Exec=/usr/bin/python3.9
Icon=/usr/share/pixmaps/python3.9.xpm
Terminal=true
Type=Application
Categories=Development;
StartupNotify=true
NoDisplay=true
# git-cola.desktop
[Desktop Entry]
Name=Git Cola
Comment=The highly caffeinated Git GUI
Comment[cs]=Git GUI s vysokým obsahem kofeinu
Comment[zh_TW]=高咖啡因含量的 Git 圖形介面
TryExec=git-cola
Exec=git-cola --prompt
Icon=git-cola
StartupNotify=true
Terminal=false
Type=Application
Categories=Development;RevisionControl;
X-KDE-SubstituteUID=false
# yad-icon-browser.desktop
[Desktop Entry]
Encoding=UTF-8
Name=Icon Browser
Name[fr]=Navigateur d'Icônes
Name[it]=Navigatore di icone
Name[pt_BR]=Ícone do navegador
Name[ru]=Броузер иконок
Name[sk]=Prehliadač ikon
Name[uk]=Павігатор іконок
Name[zh_TW]=圖示瀏覽器
Comment=Inspect GTK Icon Theme
Comment[fr]=Parcourir les icônes du thème GTK
Comment[it]=Sfoglia le icone del tema GTK
Comment[pt_BR]=Inspecionar ícone tema do GTK
Comment[ru]=Исследование темы иконок GTK
Comment[sk]=Preskúmať tému ikon GTK
Comment[uk]=Перегляд теми іконок GTK
Comment[zh_TW]=檢閱 GTK 圖示布景主題
Categories=GTK;Development;
Exec=yad-icon-browser
Icon=yad
Terminal=false
Type=Application
StartupNotify=true
# featherpad.desktop
[Desktop Entry]
Name=FeatherPad
GenericName=Text Editor
GenericName[cs]=Textový editor
GenericName[da]=Tekstredigering
GenericName[de]=Texteditor
GenericName[es]=Editor de texto
GenericName[eo]=Tekst-Redaktilo
GenericName[fa]=ويرايشگر متن
GenericName[hu]=Szövegszerkesztő
GenericName[it]=Editor di testo
GenericName[ja_JP]=テキストエディタ(Qt)
GenericName[pl]=Edytor tekstu
GenericName[pt]=Editor de texto
GenericName[ru]=Текстовый редактор
GenericName[sv]=Textredigering
GenericName[tr]=Metin Düzenleyici
GenericName[zh_CN]=文本编辑器
Comment=Lightweight Qt text editor
Comment[cs]=Nenáročný textový editor, založený na Qt
Comment[da]=Letvægts Qt-tekstredigering
Comment[es]=Editor de texto ligero basado en Qt
Comment[eo]=Malpeza tekst-redaktilo bazita sur Qt
Comment[fa]=ويرايشگر سبک متن
Comment[hu]=Gyors szövegszerkesztő Qt-ben
Comment[ja_JP]=軽量 Qt テキストエディタ
Comment[pl]=Lekki edytor tekstu oparty na Qt
Comment[pt]=Editor de texto leve baseado em Qt
Comment[ru]=Лёгкий текстовый редактор на Qt
Comment[sv]=Lättviktig Qt-textredigering
Comment[tr]=Hafif Qt tabanlı metin düzenleyici
Comment[zh_CN]=轻量级 Qt 文本编辑器
Exec=featherpad %U
Icon=featherpad
Terminal=false
Type=Application
MimeType=text/plain;
Categories=Qt;Utility;TextEditor;
X-KDE-StartupNotify=false;
Keywords=Text;Editor;Plaintext;
Actions=new-window;standalone-window;
[Desktop Action new-window]
Name=New Window
Name[cs]=Nové okno
Name[de]=Neues Fenster
Name[eo]=Nova Fenestro
Name[fa]=پنجرهی جديد
Name[it]=Nuova finestra
Name[hu]=Új ablak
Name[pt]=Nova Janela
Name[sv]=Nytt Fönster
Exec=featherpad --win
[Desktop Action standalone-window]
Name=Standalone Window
Name[de]=Eigenständiges Fenster
Name[eo]=Memstara Fenestro
Name[fa]=پنجرهی مستقل
Name[sv]=Fristående Fönster
Exec=featherpad --standalone
# firefox.desktop
[Desktop Entry]
Categories=Network;WebBrowser;
Comment[en_US]=Browse the World Wide Web
Comment=Browse the World Wide Web
Comment[bg]=Сърфиране в Мрежата
Comment[ca]=Navegueu per el web
Comment[cs]=Prohlížení stránek World Wide Webu
Comment[de]=Im Internet surfen
Comment[el]=Περιηγηθείτε στον παγκόσμιο ιστό
Comment[es]=Navegue por la web
Comment[fa]=صفحات شبکه جهانی اینترنت را مرور نمایید
Comment[fi]=Selaa Internetin WWW-sivuja
Comment[fr]=Navigue sur Internet
Comment[hu]=A világháló böngészése
Comment[it]=Esplora il web
Comment[ja]=ウェブを閲覧します
Comment[ko]=웹을 돌아 다닙니다
Comment[nb]=Surf på nettet
Comment[nl]=Verken het internet
Comment[nn]=Surf på nettet
Comment[no]=Surf på nettet
Comment[pl]=Przeglądanie stron WWW
Comment[pt]=Navegue na Internet
Comment[pt_BR]=Navegue na Internet
Comment[ru]=Обозреватель Всемирной Паутины
Comment[sk]=Prehliadanie internetu
Comment[sv]=Surfa på webben
Encoding=UTF-8
Exec=firefox %u
GenericName[en_US]=Web Browser
GenericName=Web Browser
GenericName[bg]=Интернет браузър
GenericName[ca]=Navegador web
GenericName[cs]=Webový prohlížeč
GenericName[de]=Webbrowser
GenericName[el]=Περιηγητής ιστού
GenericName[es]=Navegador web
GenericName[fa]=مرورگر اینترنتی
GenericName[fi]=WWW-selain
GenericName[fr]=Navigateur Web
GenericName[hu]=Webböngésző
GenericName[it]=Browser Web
GenericName[ja]=ウェブ・ブラウザ
GenericName[ko]=웹 브라우저
GenericName[nb]=Nettleser
GenericName[nl]=Webbrowser
GenericName[nn]=Nettlesar
GenericName[no]=Nettleser
GenericName[pl]=Przeglądarka WWW
GenericName[pt]=Navegador Web
GenericName[pt_BR]=Navegador Web
GenericName[ru]=Интернет-браузер
GenericName[sk]=Internetový prehliadač
GenericName[sv]=Webbläsare
Icon=firefox
MimeType=text/html;image/png;image/jpeg;image/gif;application/xml;application/xml;application/xhtml+xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;
Name[en_US]=Firefox
Name=Firefox
Name[bg]=Firefox
Name[ca]=Firefox
Name[cs]=Firefox
Name[el]=Firefox
Name[es]=Firefox
Name[fa]=Firefox
Name[fi]=Firefox
Name[fr]=Firefox
Name[hu]=Firefox
Name[it]=Firefox
Name[ja]=Firefox
Name[ko]=Firefox
Name[nb]=Firefox
Name[nl]=Firefox
Name[nn]=Firefox
Name[no]=Firefox
Name[pl]=Firefox
Name[pt]=Firefox
Name[pt_BR]=Firefox
Name[ru]=Firefox
Name[sk]=Firefox
Name[sv]=Firefox
StartupNotify=true
StartupWMClass=Firefox
Terminal=false
TerminalOptions=
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=
X-GNOME-FullName=Firefox Web Browser
X-GNOME-FullName[bg]=Интернет браузър (Firefox)
X-GNOME-FullName[ca]=Navegador web Firefox
X-GNOME-FullName[cs]=Firefox Webový prohlížeč
X-GNOME-FullName[el]=Περιηγήτης Ιστού Firefox
X-GNOME-FullName[es]=Navegador web Firefox
X-GNOME-FullName[fa]=مرورگر اینترنتی Firefox
X-GNOME-FullName[fi]=Firefox-selain
X-GNOME-FullName[fr]=Navigateur Web Firefox
X-GNOME-FullName[hu]=Firefox webböngésző
X-GNOME-FullName[it]=Firefox Browser Web
X-GNOME-FullName[ja]=Firefox ウェブ・ブラウザ
X-GNOME-FullName[ko]=Firefox 웹 브라우저
X-GNOME-FullName[nb]=Firefox Nettleser
X-GNOME-FullName[nl]=Firefox webbrowser
X-GNOME-FullName[nn]=Firefox Nettlesar
X-GNOME-FullName[no]=Firefox Nettleser
X-GNOME-FullName[pl]=Przeglądarka WWW Firefox
X-GNOME-FullName[pt]=Firefox Navegador Web
X-GNOME-FullName[pt_BR]=Navegador Web Firefox
X-GNOME-FullName[ru]=Интернет-браузер Firefox
X-GNOME-FullName[sk]=Internetový prehliadač Firefox
X-GNOME-FullName[sv]=Webbläsaren Firefox
X-KDE-SubstituteUID=false
X-KDE-Username=
X-MultipleArgs=false