
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/applications
directory.? 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 usually move what was being dragged, in this case, it copies it.
左鍵單擊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 called gc
. We’ll need that information shortly.
我們還可以看到二進制文件稱為gc
。 我們很快將需要這些信息。

Open up an editor. We’re going to be using?gedit
, 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.0
Name[en_US]=Geocoder
GenericName[en_US]=Interesting Point Geocoder
Comment[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/gc
Path=/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 the
gc
executable.“ 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=false
Type=Application
Categories=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 of?Application, 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 to launch the application.
左鍵單擊以啟動應用程序。
Right-click it and select “Add to favorites” to add it 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.
絕對違反直覺。
翻譯自: https://www.howtogeek.com/445303/how-to-create-desktop-shortcuts-on-ubuntu/