
Ubuntu Bionic Beaver 18.04.3 Nautilus 3.26.4(文件)
桌面上或 ~/bin 中的 *.desktop 檔案顯示為應用圖標,檔案名稱將替換為檔案的 Name 鍵的值。點擊該圖示將啟動關聯的應用程式。
我有兩個檔案 - free42dec.desktop 和 free42bin.desktop - 用於啟動 HP42s 逆波蘭計算器的 Free42 模擬。但在 Nautilus(文件)中,這些文件仍然顯示為完整文件名和通用文字圖標,而不是顯示為 Free42 Decimal 和 Free42 Binary,並帶有相應的計算器圖標。另一個奇怪之處是,開啟這些檔案的「屬性」僅在「基本」標籤中顯示普通內容,但其他行為正確的 *.desktop 檔案在「基本」標籤中顯示 Exec 鍵的值。
我不是第一個遇到 *.desktop 檔案問題的人,但搜尋字詞的組合無法給我答案。我嘗試了各種建議的補救措施,但沒有任何效果。因此,在絕望中,以下是其中一個文件的文本(另一個類似):
[Desktop Entry]
Version=2.5.17
Name=Free42 Decimal
GenericName=Calculator
Comment=HP42s calculator using decimal number calculations.
Exec=free42dec -skin Realistic
Path=/usr/local/bin
Icon=/usr/share/icons/free42/free42dec.png
Terminal=false
Type=Application
Categories=Utility;Application;
##Define Actions
Actions=Quit;Free42_Binary;
[Desktop Action Quit]
Name=Quit
# Kill all free42bin or free42dec instances currently running
# Exec=pkill free42*
# Kill only free42dec instances
Exec=pkill free42dec
OnlyShowIn=Unity;
[Desktop Action Free42_Binary]
Name=Free42 Binary
# You can start the alternative calc from the right-click menu
Exec=free42bin -skin KD0GLS_Full
OnlyShowIn=Unity;
任何人都可以看到這些文件的錯誤嗎?我試圖找到一個解析器或語法檢查器,但文件沒有幫助。似乎沒有任何針對 *.desktop 檔案的特殊安裝程式。
答案1
經過更多研究後,我發現了 CLI 命令,它檢查文件desktop-file-validate
的語法和結構。*.desktop
.../usr/share/applications$ desktop-file-validate free42dec.desktop
free42dec.desktop: error: file contains line "?[Desktop Entry]", which is not a comment, a group or an entry
看著"?[Desktop Entry]"
。這?
表示 前面有一個隱藏字符[
,它是一個位元組順序標記 (BOM),指示 BigEndian 和 LittleEndian 系統如何讀取此 UTF-8 檔案。更多搜尋產生dos2unix
,一個將 Windows 文字檔案轉換為 UNIX 格式的實用程序,您可以使用
$ sudo apt install dos2unix
現在執行以下操作:
.../usr/share/applications$dos2unix free42dec.desktop
dos2unix: converting file free42dec.desktop to Unix format...
耶!現在,該free42dec.desktop
檔案出現在 Nautilus 中,/usr/share/applications
並且Name
密鑰為 Free42 Decimal 而不是檔案名,並且文字圖示更改為 Free42 Decimal 圖示。此捷徑現在顯示在啟動器儀表板和應用程式儀表板(概述)中。將其複製到桌面意味著您也可以單擊它來啟動 Free42 Decimal 應用程式。
(啟動器、捷徑)檔案的格式、結構和語法*,desktop
記錄在桌面入門規格。