1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 如何在Ubuntu上创建桌面快捷方式

如何在Ubuntu上创建桌面快捷方式

时间:2022-04-20 05:11:21

相关推荐

如何在Ubuntu上创建桌面快捷方式

Desktop icons should be simple, but they’re not on Ubuntu 18.04 LTS and newer releases like Ubuntu 19.10. Follow these easy steps to get desktop shortcuts for your favorite applications, just like on other operating systems and other Linux desktops.

桌面图标应该很简单,但不能在Ubuntu 18.04 LTS和更高版本(如Ubuntu 19.10)上使用。 按照这些简单的步骤,即可为您喜欢的应用程序获取桌面快捷方式,就像在其他操作系统和其他Linux桌面上一样。

是的,应该更容易 (Yes, It Should Be Easier)

Dropping shortcuts on the desktop is one of those things that Windows users do without overthinking about it. It’s unfortunate, but a newcomer to Linux can find doing that simple task a frustrating struggle. It’s the type of thing that gives them the impression that getting anywhere with Linux is going to be a long hard slog.

在桌面上放置快捷方式是Windows用户不加思索的事情之一。 不幸的是,但是Linux的新手会发现完成此简单任务令人沮丧。 正是这种类型给他们的印象是,要想在Linux上取得成功,将是一个漫长的艰难历程。

Even people who’ve used Linux for a little while and know their way around pretty well can find this topic much more of a struggle that it ought to be.In actual fact, it’s not difficult, but it is definitely counter-intuitive.

即使是使用Linux已有一段时间的人,也非常了解Linux的方式,他们也可以发现这个话题比以前更艰巨。 实际上,这并不难,但这绝对是违反直觉的。

安装GNOME调整 (Installing GNOME Tweaks)

By default, you can’t copy files or icons to Ubuntu’s GNOME Shell desktop. To make this possible you’ll need to use GNOME Tweaks to change a setting. Use this command to install it.

默认情况下,您不能将文件或图标复制到Ubuntu的GNOME Shell桌面。 为此,您需要使用GNOME Tweaks更改设置。 使用此命令进行安装。

sudo apt-get install gnome-tweaks

When it has installed, press the “Super” key (between the Control and Alt keys on the bottom-left of most keyboards) and type “tweaks”. The Tweaks icon will appear. Click on that to launch Tweaks.

安装后,按“超级”键(在大多数键盘的左下方,在Control和Alt键之间),然后键入“ tweaks”。 出现“调整”图标。 单击该按钮以启动“调整”。

This is the icon in Ubuntu 18.04. The icon will look different in Ubuntu 19.10. When Tweaks has launched, click on on “Desktop” in the left-hand pane. Click the “Show icons” slider button to allow desktop icons. You can choose whether you wish to have shortcuts to your home directory, the trash can, network servers, and mounted volumes shown on the desktop.

这是Ubuntu 18.04中的图标。 该图标在Ubuntu 19.10中看起来会有所不同。 启动Tweaks后,单击左侧窗格中的“桌面”。 单击“显示图标”滑块按钮以允许使用桌面图标。 您可以选择是否希望在桌面上显示主目录,垃圾箱,网络服务器和已安装卷的快捷方式。

Note that in Ubuntu 19.10, the desktop icon settings are under the Extensions settings, so click the “Extensions” entry in the left-hand pane.

请注意,在Ubuntu 19.10中,桌面图标设置位于扩展设置下,因此请单击左侧窗格中的“扩展”条目。

创建桌面快捷方式 (Creating a Desktop Shortcut)

To demonstrate this process, we’re going to create a desktop shortcut for LibreOffice writer. Now that we’ve turned on the ability to have icons on the desktop, we just need to drag something to the desktop, and we’ll have a shortcut. But what do we need to drag?

为了演示此过程,我们将为LibreOffice writer创建一个桌面快捷方式。 现在,我们已经启用了在桌面上显示图标的功能,我们只需要将某些东西拖到桌面上,就会有一个快捷方式。 但是,我们需要拖动什么?

It’s something called an application’s .desktop file. These are text files that describe certain attributes about the application. Amongst other things, they tell the operating system where the binary executable resides in the file system. When you double-click the shortcut, Linux uses this information to find and launch the application’s binary file. We just need to find the right .desktop file.

这就是所谓的应用程序的.desktop文件。 这些是描述有关应用程序某些属性的文本文件。 除其他外,它们告诉操作系统二进制可执行文件在文件系统中的位置。 当您双击快捷方式时,Linux使用此信息来查找并启动应用程序的二进制文件。 我们只需要找到正确的.desktop文件。

Applications that are provided as part of a distribution’s default packages, or are installed from repositories, have their .desktop files installed into:

作为发行版默认软件包的一部分提供的应用程序,或从存储库安装的应用程序的.desktop文件安装到:

/usr/local/share/applications

Other applications that have been locally installed with system-wide access—meaning they are available for all users—usually have their .desktop files installed into:

在本地安装并具有系统范围访问权限的其他应用程序(意味着它们对所有用户都可用)通常将其.desktop文件安装到:

/usr/local/share/applications

Applications that have been installed so that they are only accessible to a single user have their .desktop files installed into the home directory of that user:

已安装的应用程序(仅供单个用户访问)将.desktop文件安装到该用户的主目录中:

~/.local.share/applications

LibreOffice is available for all users, so we’re going to launch Files and browse to the/usr/share/applicationsdirectory. You’ll need to navigate to the appropriate directory for the application you’re looking for.

LibreOffice适用于所有用户,因此我们将启动“文件”并浏览到/usr/share/applications目录。 您需要导航到要查找的应用程序的适当目录。

Launch Files, and click on “Other locations” in the left-hand pane. Then navigate to Computer > usr > share > applications.

启动文件,然后单击左侧窗格中的“其他位置”。 然后导航至计算机> usr>共享>应用程序。

Scroll through the icons until you see the LibreOffice Writer icon. In Ubuntu 19.10, the icons all look like cogged wheels, so you’ll need to check the name of the file to make sure you have the correct .desktop file.

滚动浏览图标,直到看到LibreOffice Writer图标。 在Ubuntu 19.10中,所有图标看起来都像齿轮,因此您需要检查文件名以确保具有正确的.desktop文件。

To make certain you’ve found the .desktop file of the application you’re looking for, right-click the icon and select properties. You should see a line telling you this is a desktop configuration file. Close the properties dialog.

为确保已找到要查找的应用程序的.desktop文件,请右键单击该图标并选择属性。 您应该看到一行告诉您这是一个桌面配置文件。 关闭属性对话框。

Left-click on the LibreOffice Writer icon, hold the left mouse button down, and drag the icon to the desktop. Release the mouse button. Although this would usuallymovewhat was being dragged, in this case, itcopiesit.

左键单击LibreOffice Writer图标,按住鼠标左键,然后将图标拖到桌面。 释放鼠标按钮。 尽管这通常会移动被拖动的内容,但在这种情况下,它会对其进行复制。

You’ve now got an icon on the desktop, but it doesn’t look anything like it should. What’s going on?

现在,您已经在桌面上有了一个图标,但是它看起来并不像它应该的样子。 这是怎么回事?

Although it doesn’t look like you’d expect, it is a working shortcut. Double-click it to launch the application, and you’ll be greeted with a warning dialog.

尽管看起来不像您期望的那样,但这是一个有效的捷径。 双击它以启动该应用程序,然后会出现一个警告对话框。

Click the “Trust and launch” button, and two things will happen.

单击“信任并启动”按钮,将发生两件事。

The icon will change its appearance and text label to look like you’d expect it to, and LibreOffice Writer will be launched.

该图标将更改其外观和文本标签,使其看起来像您期望的那样,然后将启动LibreOffice Writer。

You now have a LibreOffice Writer icon on the desktop that can be used as a shortcut to launch the application. You’ll only see the “Untrusted Application Launcher” dialog the first time you use the shortcut.

现在,您在桌面上有一个LibreOffice Writer图标,可以用作启动该应用程序的快捷方式。 首次使用快捷方式时,您只会看到“不受信任的应用程序启动器”对话框。

如果.desktop文件丢失怎么办? (What if the .desktop File is Missing?)

Sometimes applications do not provide a .desktop file. Programs that have been written in-house or applications you might have downloaded from Github, for example, often don’t come with a .desktop file.

有时应用程序不提供.desktop文件。 例如,内部编写的程序或您可能从Github下载的应用程序通常不带有.desktop文件。

That’s not a problem; we can easily create our own. All it is is a text file with the appropriate details listed in it.

那不是问题; 我们可以轻松创建自己的。 它只是一个文本文件,上面列出了适当的详细信息。

创建一个.desktop文件 (Creating a .desktop File)

On this test computer, we’ve got a program that doesn’t have a .desktop file.

在这台测试计算机上,我们有一个没有.desktop文件的程序。

The first thing to do is to check that the application runs. If it doesn’t, you’re not going to get it working with a .desktop file either. But you can spend a lot of time going round in circles wondering why your .desktop file doesn’t work. So, for the sake of being thorough, ensure you’re application launches and runs correctly when you start it manually.

首先要做的是检查应用程序是否运行。 如果没有,您也不会使用.desktop文件。 但是您可能会花很多时间盘算,想知道为什么您的.desktop文件不起作用。 因此,为彻底起见,请确保您在手动启动应用程序时启动并正确运行了应用程序。

A .desktop file is a text file with settings it in. On its own, that isn’t enough to display an icon. We need to use an icon that has been supplied with the application. We can see there is an icon called “ip_gc_icon.png” in the application directory, and we’ll use that.

.desktop文件是带有设置内容的文本文件。仅靠它本身不足以显示图标。 我们需要使用应用程序随附的图标。 我们可以看到应用程序目录中有一个名为“ ip_gc_icon.png”的图标,我们将使用它。

We can also see that the binary file is calledgc. We’ll need that information shortly.

我们还可以看到二进制文件称为gc。 我们很快将需要这些信息。

Open up an editor. We’re going to be usinggedit, but you can use the editor of your choice.

打开一个编辑器。 我们将使用gedit,但是您可以使用自己选择的编辑器。

The first line of the .desktop file must be:

.desktop文件的第一行必须是:

[Desktop Entry]

This identifies to Linux what it is you’re clicking on when you double-click it.

这将向Linux标识您双击它时要单击的内容。

All of the other entries in the .desktop file are composed of labels and values, joined by an equals sign=. Make sure you don’t have spaces directly before or after the equals sign.

.desktop文件中的所有其他条目均由标签和值组成,并由等号=。 确保在等号之前或之后没有空格。

The next four lines describe the application.

接下来的四行描述了该应用程序。

Version=1.0Name[en_US]=GeocoderGenericName[en_US]=Interesting Point GeocoderComment[en_US]=Interesting Point Geocoder is a tool to create CSV files of geolocational data

The “Version” entry is the version number from the program.“版本”条目是程序的版本号。 The “Name” entry is the name of the application. Note that we’ve included a locale identifier, [en_US], which means US English. You could leave it out. If you were creating a multi-lingual .desktop file, these types of identifiers would be required for each different language section. They won’t make any difference here, but they’re a good habit to get into.“名称”条目是应用程序的名称。 请注意,我们包括了一个语言环境标识符[en_US],表示美国英语。 您可以忽略它。 如果要创建多语言的.desktop文件,则每种不同的语言部分都需要使用这些类型的标识符。 他们在这里没有任何区别,但是他们是一个很好的习惯。 The “GenericName” entry is used to hold a generic description of the application. This could be used to hold descriptions such as “video editor,” “web browser,” or “word processor.” This application doesn’t fall into any particular category, so we’ll just give it a longer version of the application name.“ GenericName”条目用于保存应用程序的一般描述。 它可以用来保存诸如“视频编辑器”,“ Web浏览器”或“文字处理器”之类的描述。 该应用程序不属于任何特定类别,因此我们只给它更长的版本。 The “Comment” entry can hold any descriptive text you like.“注释”条目可以包含您喜欢的任何描述性文本。

The next three lines provide information to Linux so that it knows where the binary executable is, and which icon it should use for the shortcut.

接下来的三行向Linux提供信息,以便它知道二进制可执行文件在哪里,以及该快捷方式应使用哪个图标。

Exec=/home/dave/geocoder/gcPath=/home/dave/geocoder/Icon=/home/dave/geocoder/ip_gc_icon.png

The “Exec” entry is the path to the binary executable. In our example, this is thegcexecutable.

“ Exec”条目是二进制可执行文件的路径。 在我们的示例中,这是gc可执行文件。

The “Path” entry is the path to the working directory for the application.“路径”条目是应用程序工作目录的路径。 The “Icon” entry is the path to the icon file that you wish to use for the desktop shortcut.“图标”条目是您要用于桌面快捷方式的图标文件的路径。

The last three lines are supplementary data regarding the application.

最后三行是有关应用程序的补充数据。

Terminal=falseType=ApplicationCategories=Application

The “Terminal” entry can be True or False. It indicates whether the application executes in a terminal or not. Our entry needs to be “false”.“终端”条目可以为True或False。 它指示应用程序是否在终端中执行。 我们的输入必须为“ false”。 The “Type” entry can be one ofApplication, Link, or Directory. Obviously, we want our entry to be “Application”.“类型”条目可以是“应用程序”,“链接”或“目录”之一。 显然,我们希望我们的条目为“ Application”。 The “Categories” entry may be used by Linux or GNOME to group similar or related applications in menus. We’re just going to enter a generic “Applications.”Linux或GNOME可以使用“类别”条目将菜单中的相似或相关应用程序分组。 我们将要输入通用的“应用程序”。

A full list of possible .desktop file entries and their values can be found in the .desktop file specification.

可能的.desktop文件条目及其值的完整列表可以在.desktop文件规范中找到。

Here’s our complete .desktop file:

这是我们完整的.desktop文件:

Save the file into the application directory, making sure it has a “.desktop” file extension. Our example file is called “Geocoder.desktop.”

将文件保存到应用程序目录中,确保文件扩展名为“ .desktop”。 我们的示例文件称为“ Geocoder.desktop”。

将.desktop文件复制到桌面 (Copying the .desktop FIle To the Desktop)

To copy the .desktop file onto the desktop, right-click it and select “Copy” from the context menu. Right-click on the desktop and select “Paste” from the context menu.

要将.desktop文件复制到桌面上,请右键单击该文件,然后从上下文菜单中选择“复制”。 右键单击桌面,然后从上下文菜单中选择“粘贴”。

When you double click the icon on the desktop, you’ll see the same warning dialog as earlier. Click the “Trust and Launch” button.

双击桌面上的图标时,您将看到与之前相同的警告对话框。 单击“信任并启动”按钮。

The desktop icon will take on its true appearance, and the application will be launched.

桌面图标将显示其真实外观,然后将启动该应用程序。

将.desktop文件复制到Applications文件夹 (Copying the .desktop FIle To the Applications Folder)

As this program is going to be used by a single user, we’ll copy the .desktop file to his local applications directory. In the program directory, use this command:

由于该程序将由单个用户使用,因此我们将.desktop文件复制到他的本地应用程序目录中。 在程序目录中,使用以下命令:

cp ./Geocoder.desktop ~/.local/share/applications

Putting the .desktop file in the local applications directory integrates the application into the GNOME search function.Press the “Super” key (between the Control and Alt keys on the bottom-left of most keyboards) and type the first part of your application’s name. Its icon will appear in the search results.

将.desktop文件放在本地应用程序目录中,会将应用程序集成到GNOME搜索功能中。 按“超级”键(在大多数键盘的左下角,在Control和Alt键之间),然后键入应用程序名称的第一部分。 其图标将出现在搜索结果中。

Left-Click it tolaunchthe application.

左键单击以启动应用程序。

Right-click it and select “Add to favorites” toaddit to your Ubuntu dock.

右键单击它,然后选择“添加到收藏夹”将其添加到您的Ubuntu扩展坞。

准备发射 (Ready for Launch)

So there you have it. A little long-winded, but simple enough.

所以你有它。 有点long,但是很简单。

And definitely counter-intuitive.

绝对违反直觉。

翻译自: /445303/how-to-create-desktop-shortcuts-on-ubuntu/

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。