Linux管理员打开快捷方式,Desktop Entry创建Linux程序的快捷方式

1.Desktop  Entry文件

在windows操作系统里,打开程序可以通过点桌面上的快捷方式文件打开。在Linux系统上,程序的打开快捷方式文件是由Desktop Entry文件来描述的,它描述了程序的启动配置信息。Desktop Entry文件标准是由FreeDesktop.org(http://freedesktop.org/wiki/)制定的,目前最新的版本是Version 1.2alpha。我们用1.0就好了。Desktop Entry文件以".desktop"为后缀名。这些Desktop  Entry文件通常会放在/usr/share/applications/或/opt/gnome/share/applications/等目录下,但其实放哪里都可以。用户打开应用程序浏览器后会看见很多应用程序快捷方式,每个快捷方式都和一个Desktop  Entry文件相对应。点击相应Desktop  Entry文件同样可以启动相对应的应用程序。一个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文件结构

Desktop Entry文件以字符串"[Desktop Entry]"开始。Desktop Entry文件的内容是由若干“key=value”的键值对组成的。key分为必选和可选两种:必选的必须在.desktop文件中被定义;而可选则不必。下面是关于一些重要关键字的说明:

Version:可选,指定了当前Desktop Entry文件所遵循的Desktop Entry文件标准版本。

Name:必选,指定了快捷方式显示的名称。

Icon:[可选]指定义了快捷方式所使用的图标。

Icon如果指定的图标是以绝对路径的格式给出,那么所指定图标文件将被使用;如果只给出了图标的名称,那么Linux系统将使用"IconTheme Specification",也就说从系统指定的主题下去找这个图标,这些主题的图标放在/usr/share/icons的对应的主题下,如果系统没有指定主题,那么就会加载hicolor主题下的图标。原文是这样说的:

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:[可选]指定了应用程序的通用名称。如果程序名系:谷歌浏览器,那么这个通用的名称可以系:浏览器。有些分类的意思。

Comment:[可选]对当前快捷方式对应的程序的简单描述。

Type:[必选]指定了Desktop Entry文件的类型。数值可以是"Application"或"Link"。"Type= Application"表示当前Desktop Entry文件指向了一个应用程序;而"Type = Link"表示当前Desktop Entry文件指向了一个URL。

Exec:[可选]只有在"Type"类型是"Application"时才有意义。定义了启动指定应用程序所要执行的命令,在此命令是可以带参数的。所执行的命令在shell中输入并按回车键同样可以启动指定应用程序。

URL:[可选]只有在"Type"类型是"Link"时才有意义。"URL"的数值定义了该Desktop

Entry文件指向的URL。

StartupNotify:[可选]值只能是true或false,只有在"Type"类型是"Application"时才有意义。用于跟踪程序的启动。参考:https://www.freedesktop.org/wiki/Specifications/startup-notification-spec/

Terminal:[可选]数值也是布尔值,只有在"Type"类型是"Application"时才有意义。指出将要运行的程序是否需要在终端窗口中运行

Categories:[可选]只有在"Type"类型是"Application"时才有意义。指出了将要运行的程序在菜单中显示的类别。参考:https://specifications.freedesktop.org/menu-spec/menu-spec-1.0.html

在关键字后加上字符串"[LOCALE]"就可以对该关键字进行特定的本地化定义,也就是说根据系统所选的语言去选用相应的键值。"LOCALE"的合法取值为:

LOCALE= lang_COUNTRY.ENCODING@MODIFIER

在此,域"_COUNTRY",".ENCODING"和"@MODIFIER"是可以被忽略的。当指定Desktop

Entry文件被解析时,解析器应当根据当前POSIX

locale来正确获取本地化的关键字数值。如前就分别定义了在"cs"和"hu"语言环境下关键字"Name","Comment"和"GenericName"的不同值。

下载创建几个小实例:

如在桌面创建打开百度的快捷方式,我准备了一个baidu.png图标:

[Desktop

Entry]

Version=1.0

Name=百度一下

Icon=/home/won/Icons/baidu.png

Type=Link

把这个文件件放在桌面,一点击,就打开百度了。

再来一个打开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

效果如下:

ebcffc0a06cf

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值