この記事を作った動機
GNOME デスクトップ環境などにおいて特定のスクリプトを実行するなど、定型処理を気軽に行うために、ショートカット(デスクトップエントリ)を作成したいということがあった。しかし、.desktopという拡張子を持つファイルを所定の場所に作れば、ショートカットができることがわかっていたものの、その内容がめんどくさくて、放置していたことがあった。
そこで今回はExample Desktop Entry File | Desktop Entry Specificationの.desktopエントリの例を参考に、最低限私が使いたいように加工した物をテンプレートとして記録しておくことにした。
事前情報
[userName]と書かれている部分は、適宜存在するユーザのホームディレクトリ名などに書き換える。
設定内容
.desktopの内容
スクリプトを実行する場合には、Terminal=trueを指定すること、実行権限を付与すること(“chmod +x [対象のスクリプトやバイナリ]")やインタプリンタなどを指定するシバンが先頭に必要である。(例:”#!/bin/bash","#!/bin/python")
[Desktop Entry]
Version=1.0
Type=Application
Name=A sample sortcut
Comment=This is a sample desktop entry text.
Terminal=true
Exec=/path/to/script.sh
Icon=[icons フォルダ直下に配置した画像名か、画像までのファイル名を含めた絶対パス 拡張子も書く]
.desktopのファイルの配置場所
特定のユーザだけ
/home/[userName]/.local/share/applications
全体に反映
/usr/share/applications
アイコン画像の配置場所と利用方法
icons フォルダに直接画像を配置する場合は、デスクトップエントリの記述においてIcon=[拡張子を含めたファイル名]で通り、すべてのパスを書く必要はない。階層構造を作るには、Icon Theme Specification に従って厳密にインデックスなどをテキストで指定する必要があり手間がかかるので今回は省略する。それ以外の場所に配置する場合は、デスクトップエントリの記述においてIcon=[画像のファイル名を含めた絶対パス]とする必要がある。
特定のユーザだけ
/home/[userName]/.local/share/icons
全体に反映
/usr/share/icons
例
例として、ゆっくり霊夢をアイコンとしたecho "ゆっくりしていってね!"を実行するスクリプトへのショートカットの作成について、以下に示す。
.desktopファイル
配置場所
/home/[userName]/.local/share/applications/yukkuri.desktop
内容
[Desktop Entry]
Version=1.0
Type=Application
Name=Yukkuri say something meaningless
Comment=Yukkuri will say something meaningless.
Terminal=true
Exec=/home/[userName]/script/yukkuri/say.sh
Icon=/home/[userName]/.local/share/icons/yukkuri/reimu/normal.png
スクリプト
配置場所
/home/[userName]/script/yukkuri/say.sh
内容
#!/bin/bash
echo "ゆっくりしていってね!"
画像
配置場所
/home/[userName]/.local/share/icons/yukkuri/reimu/normal.png
ゆっくり霊夢の画像 (normal.png)
動作例
期待したとおりに動作している例
アイコン反映に失敗している例
使った画像とか
- nicotalk&キャラ素材配布所 (ゆっくり霊夢の画像)
http://www.nicotalk.com/charasozai_kt.html (2026年4月2日)
参考にしたサイトとか
- Example Desktop Entry File | Desktop Entry Specification
https://specifications.freedesktop.org/desktop-entry/latest/example.html (2026年4月2日) - Recognized desktop entry keys | Desktop Entry Specification
https://specifications.freedesktop.org/desktop-entry/latest/recognized-keys.html (2026年4月2日) - Desktop Entry Specification
https://specifications.freedesktop.org/desktop-entry/latest/index.html (2026年4月2日) - Icon Theme Specification
https://specifications.freedesktop.org/icon-theme/latest/#icon_lookup (2026年4月2日) - Where to get list of icons to use? - Desktop - GNOME Discourse
https://discourse.gnome.org/t/where-to-get-list-of-icons-to-use/21244 (2026年4月2日) - Where are the icons for an application in the Gnome App Launcher stored? : r/Fedora
https://www.reddit.com/r/Fedora/comments/u5piht/where_are_the_icons_for_an_application_in_the/ (2026年4月2日)