如何获取 *.desktop 文件来启动应用程序并在桌面和 /usr/share/applications/ 中显示名称和应用程序图标?

如何获取 *.desktop 文件来启动应用程序并在桌面和 /usr/share/applications/ 中显示名称和应用程序图标?

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键是NameFree42 Decimal,而不是文件名,文本图标变为 Free42 Decimal 图标。此快捷方式现在出现在启动器面板和应用程序面板(概览)中。将其复制到桌面意味着您也可以在那里单击它来启动 Free42 Decimal 应用程序。

启动器、快捷方式文件的格式、结构和语法*,desktop记录在桌面入门规格

相关内容