將應用程式新增到gnome3的全域性選單中(並支援修改為預設程式)
在gnome3中,如果將滑鼠移動到左上角,就會出現一個程式選單,類似於win8中的start介面,在這裡直接鍵入英文就可以快速索引程式,十分方便。不過像deadbeef(筆者喜歡的一個輕量級音樂播放器)這種從網上獲取的可執行檔案無法作為程式出現在gnome3的程式選單中,而且也無法新增為播放.mp3的預設程式,所以才需要使用如下方法
# cd /usr/share/applications/
# vim deadbeef.desktop
[Desktop Entry]
Name=Deadbeef
GenericName=Music Player
Comment=Deadbeef
Exec=/home/yting/Downloads/deadbeef-0.6.2/deadbeef %U
Icon=/home/yting/Downloads/deadbeef-0.6.2/deadbeef.png
Terminal=false
Type=Application
Categories=Music
StartupNotify=false
這裡說明一下,關鍵是我們自己建立的.desktop檔案,這個檔案可以放到兩個目錄下起作用,分別是~/.local/share/applications與cd /usr/share/applications/,如果放到前者下,則僅對當前使用者有效,如果放到後一個目錄,則所有使用者都可以直接在gnome3程式選單中執行該程式
.desktop檔案中的格式是固定的,下面解釋一下:
[Desktop Entry]->固定,不可變
Name=Deadbeef->名字直接影響索引,按照程式的不同可以換不同名字
GenericName=Music Player->這行可以去掉
Comment=Deadbeef
Exec=/home/yting/Downloads/deadbeef-0.6.2/deadbeef %U->重點在這,路徑不能寫錯,後面的%U在Table1-2說明
Icon=/home/yting/Downloads/deadbeef-0.6.2/deadbeef.png->圖示
Terminal=false->不在終端執行
Type=Application->說明這是個應用,其他可選值(Link,Directory)
Categories=Music
StartupNotify=false
Add... | Accepts... |
---|---|
%f | a single filename. |
%F | multiple filenames. |
%u | a single URL. |
%U | multiple URLs. |
%d | a single directory. Used in conjunction with %f to locate a file. |
%D | multiple directories. Used in conjunction with %F to locate files. |
%n | a single filename without a path. |
%N | multiple filenames without paths. |
%k | a URI or local filename of the location of the desktop file. |
%v | the name of the Device entry. |