1.Desktop ?Entry文件
在windows操作系統(tǒng)里,打開程序可以通過點(diǎn)桌面上的快捷方式文件打開。在Linux系統(tǒng)上,程序的打開快捷方式文件是由Desktop Entry文件來描述的,它描述了程序的啟動(dòng)配置信息。Desktop Entry文件標(biāo)準(zhǔn)是由FreeDesktop.org(http://freedesktop.org/wiki/)制定的,目前最新的版本是Version 1.2alpha。我們用1.0就好了。Desktop Entry文件以".desktop"為后綴名。這些Desktop ?Entry文件通常會(huì)放在/usr/share/applications/或/opt/gnome/share/applications/等目錄下,但其實(shí)放哪里都可以。用戶打開應(yīng)用程序?yàn)g覽器后會(huì)看見很多應(yīng)用程序快捷方式,每個(gè)快捷方式都和一個(gè)Desktop ?Entry文件相對(duì)應(yīng)。點(diǎn)擊相應(yīng)Desktop ?Entry文件同樣可以啟動(dòng)相對(duì)應(yīng)的應(yīng)用程序。一個(gè)DesktopEntry文件的樣子大概如下:
[Desktop Entry]
Version = 1.0
Encoding = UTF-8
Name = Quick Start Tour
GenericName = User Tutorial
Comment = help you learn how to use the Desktop
Exec = gnome-open
/usr/share/doc/manual/sled-gnome-cbt_en/index.html
Icon = cbt
StartupNotify = true
Terminal = false
Type = Application
Categories = GNOME;Application;Documentation;
OnlyShowIn = GNOME;
X-SUSE-translate = true
Name[cs] = Rychlá prohlídka systému
Comment[cs] = V?ukov? program seznamující
u?ivatele se základy pracovního prost?edí
GenericName[cs] = U?ivatelsk? tutoriál
Name[hu] = Rendszerbemutató
Comment[hu] = A munkaállomés használatát
bemutató segédlet
GenericName[hu] = Felhasználói segédlet
2.Desktop ?Entry文件結(jié)構(gòu)
Desktop Entry文件以字符串"[Desktop Entry]"開始。Desktop Entry文件的內(nèi)容是由若干“key=value”的鍵值對(duì)組成的。key分為必選和可選兩種:必選的必須在.desktop文件中被定義;而可選則不必。下面是關(guān)于一些重要關(guān)鍵字的說明:
Version:可選,指定了當(dāng)前Desktop Entry文件所遵循的Desktop Entry文件標(biāo)準(zhǔn)版本。
Name:必選,指定了快捷方式顯示的名稱。
Icon:[可選]指定義了快捷方式所使用的圖標(biāo)。
Icon如果指定的圖標(biāo)是以絕對(duì)路徑的格式給出,那么所指定圖標(biāo)文件將被使用;如果只給出了圖標(biāo)的名稱,那么Linux系統(tǒng)將使用"IconTheme Specification",也就說從系統(tǒng)指定的主題下去找這個(gè)圖標(biāo),這些主題的圖標(biāo)放在/usr/share/icons的對(duì)應(yīng)的主題下,如果系統(tǒng)沒有指定主題,那么就會(huì)加載hicolor主題下的圖標(biāo)。原文是這樣說的:
The ?name of the theme that this theme inherits from. If an icon name is not found in the current theme, it is searched for in the inherited theme (and recursively in all the inherited themes).If no theme is specified implementations are required to add the"hicolor" theme to the inheritance tree. An implementation may optionally add other default themes in between the last specified theme and the hicolor theme.
參考:https://specifications.freedesktop.org/icon-theme-spec/icon-theme-spec-0.9.html
GenericName:[可選]指定了應(yīng)用程序的通用名稱。如果程序名系:谷歌瀏覽器,那么這個(gè)通用的名稱可以系:瀏覽器。有些分類的意思。
Comment:[可選]對(duì)當(dāng)前快捷方式對(duì)應(yīng)的程序的簡(jiǎn)單描述。
Type:[必選]指定了Desktop Entry文件的類型。數(shù)值可以是"Application"或"Link"。"Type= Application"表示當(dāng)前Desktop Entry文件指向了一個(gè)應(yīng)用程序;而"Type = Link"表示當(dāng)前Desktop Entry文件指向了一個(gè)URL。
Exec:[可選]只有在"Type"類型是"Application"時(shí)才有意義。定義了啟動(dòng)指定應(yīng)用程序所要執(zhí)行的命令,在此命令是可以帶參數(shù)的。所執(zhí)行的命令在shell中輸入并按回車鍵同樣可以啟動(dòng)指定應(yīng)用程序。
URL:[可選]只有在"Type"類型是"Link"時(shí)才有意義。"URL"的數(shù)值定義了該Desktop
Entry文件指向的URL。
StartupNotify:[可選]值只能是true或false,只有在"Type"類型是"Application"時(shí)才有意義。用于跟蹤程序的啟動(dòng)。參考:https://www.freedesktop.org/wiki/Specifications/startup-notification-spec/
Terminal:[可選]數(shù)值也是布爾值,只有在"Type"類型是"Application"時(shí)才有意義。指出將要運(yùn)行的程序是否需要在終端窗口中運(yùn)行
Categories:[可選]只有在"Type"類型是"Application"時(shí)才有意義。指出了將要運(yùn)行的程序在菜單中顯示的類別。參考:https://specifications.freedesktop.org/menu-spec/menu-spec-1.0.html
在關(guān)鍵字后加上字符串"[LOCALE]"就可以對(duì)該關(guān)鍵字進(jìn)行特定的本地化定義,也就是說根據(jù)系統(tǒng)所選的語言去選用相應(yīng)的鍵值。"LOCALE"的合法取值為:
LOCALE= lang_COUNTRY.ENCODING@MODIFIER
在此,域"_COUNTRY",".ENCODING"和"@MODIFIER"是可以被忽略的。當(dāng)指定Desktop
Entry文件被解析時(shí),解析器應(yīng)當(dāng)根據(jù)當(dāng)前POSIX
locale來正確獲取本地化的關(guān)鍵字?jǐn)?shù)值。如前就分別定義了在"cs"和"hu"語言環(huán)境下關(guān)鍵字"Name","Comment"和"GenericName"的不同值。
下載創(chuàng)建幾個(gè)小實(shí)例:
如在桌面創(chuàng)建打開百度的快捷方式,我準(zhǔn)備了一個(gè)baidu.png圖標(biāo):
[Desktop
Entry]
Version=1.0
Name=百度一下
Icon=/home/won/Icons/baidu.png
Type=Link
把這個(gè)文件件放在桌面,一點(diǎn)擊,就打開百度了。
再來一個(gè)打開androidstudio IDE的:
[Desktop
Entry]
Version=1.0
Name=Android
Studio
Icon=/home/won/Icons/studio.png
Type=Application
Exec=/home/won/Software/android-studio/bin/studio.sh
效果如下:
