A .desktop launcher file can likely just be (sort of) simplified down to something like the following
[Desktop Entry]
Type=Application
Name=Google Maps
Exec=google-chrome --app=https://www.google.co.uk/maps/@52.0547887,-1.3424413,11z
Comment=Open Google Maps
GenericName=Open Google Maps
Icon=/home/wilf/.local/Google-Maps-icon.png
Categories=GTK;Utility;
Keywords=Maps;
Hidden=false
NoDisplay=false
Terminal=false
Where:
- You need both
[Desktop Entry]
and Type=Application
to say it is a application launcher.
Name
is its name
Exec
is the command it runs
Comment
/GenericName
desribe it (not always needed)
Icon
is the path to a icon or a icon from the theme(s) you are using in /usr/share/icons
(not always needed, but the default icon if often annoying)
Categories
- specifies the category it is in (useful for menus - not always needed)
Keywords
are words that can be used to find it when you search for it (not always needed).
Hidden
/NoDisplay
set to false make sure it is displayed (not always needed).
Terminal
whether to run in terminal or not`.
For changing the icon, you just need to change the Icon
line to specify a different icon - e.g. to use a text editor icon from /usr/share/icons
:
Icon=accessories-text-editor
or you can specify a path to a icon file
Icon=/home/wilf/.local/Google-Maps-icon.png
This is also possible by right-clicking on the launcher in most file mangers and selecting properties:
Then clicking on the icon and selecting a new one - note if it is in /usr/share/applications
you probably need permissions to edit the file.
N.B.
I can't exactly remember why (probably made it for something), but I appear to have the following script that can create .desktop launchers - here it is:
#!/bin/bash
if [ "$1" = "--help" ]; then
echo -e "\e[1mUsage:\e[0m\n create-launcher [OPTIONS...] [FILENAME] - create a launcher\n\e[1mHelp Options:\e[0m\n --help Show help options\n\e[1mApplication Options:\e[0m\n -n NAME Sets the name of the New launcher\n -c COMMAND Sets the command the launcher will be used to Launch\n -t COMMENT Sets the comment used to describe the launcher\n -i ICON Specifies an icon filename or stock icon to display.\n\n\e[1mNote\e[0m - ideally all of the above options should be used, mainly the Name option as it used to create the name of the launcher, and the command option as that is required for the launcher to work."
exit
fi
while getopts n:c:t:i: option
do
case "${option}"
in
n) NAME=${OPTARG};;
c) COMMAND=${OPTARG};;
t) COMMENT=${OPTARG};;
i) ICON=${OPTARG};;
esac
done
FILE=$HOME/.local/share/applications/$(echo $NAME | sed 's/ /-/g').desktop
NOFILE=$HOME/.local/share/applications/.desktop
if [ $FILE = $NOFILE ]; then
echo -e "ERROR: Please enter atleast the Name for the launcher - for more info run\n create-launcher --help"
exit 1
else
echo "New launcher created at $FILE"
echo -e "[Desktop Entry]\nType=Application" > $FILE
echo Name=$NAME >> $FILE
echo Exec=$COMMAND >> $FILE
echo Comment=$COMMENT >> $FILE
echo Icon=$ICON >> $FILE
echo -e "Hidden=false\nNoDisplay=false\nTerminal=false\n#X-GNOME-Autostart-enabled=true" >> $FILE
chmod +x $FILE
fi
exit
This can be saved to a executable file, and creates a simple launcher like the following (except the fields are filled by specifying the scripts options - see ./create-launcher --help
) in ~/.local/share/applications
(which should mean the launcher shows in menus etc)
[Desktop Entry]
Type=Application
Name=
Exec=
Comment=
Icon=
Hidden=false
NoDisplay=false
Terminal=false
#X-GNOME-Autostart-enabled=true
The last line is not important unless it is used elsewhere to start a program on login.