0

Using only terminal commands, preferably without su privileges, is there a way to create a shortcut on Ubuntu desktop and specify the icon.png to be shown on the desktop for the new shortcut?

Edit to original question follows.

I have created register.sh which creates MyGame.desktop and copies it to Desktop folder. This works ok but I still have to press F5 to update the desktop view for the correct icon to be displayed. Is there a terminal command that updates the desktop view in the same way that pressing F5 does? Tried installing xdotool to 'press F5' but that doesn't seem to work in the following script.

register.sh

#!/bin/bash

cd /home/jah/MyGame

echo "[Desktop Entry]" > MyGame.desktop

echo "Name=MyGame" >> MyGame.desktop

echo "Type=Application" >> MyGame.desktop

echo "Categories=Game;" >> MyGame.desktop

echo "Terminal=false" >> MyGame.desktop

echo "Exec=/home/jah/MyGame/MyGame" >> MyGame.desktop

echo "Icon=/home/jah/MyGame/MyGame.png" >> MyGame.desktop

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

chmod 755 ~/.local/share/applications/MyGame.desktop

cp MyGame.desktop ~/Desktop

chmod 755 ~/Desktop/MyGame.desktop

gio set ~/Desktop/MyGame.desktop "metadata::trusted" yes

gio info ~/Desktop/MyGame.desktop >gioinfo.log

xdotool key F5

2 Answers2

0

For sure one can create an Ubuntu desktop shortcut with terminal commands. Such desktop shortcuts are specially formatted text files with a .desktop extension. They are used to populate your application menu, and can function as launchers on the desktop. Just echo the different lines to a file, e.g. as in:

echo [Desktop Entry]                   > ~/Desktop/myfirefox.desktop
echo Name=Firefox Web Browser          >> ~/Desktop/myfirefox.desktop
echo Comment=Browse the World Wide Web >> ~/Desktop/myfirefox.desktop
echo Icon=firefox
...

Another approach:

cat >> ~/Desktop/myfirefox.desktop << EOF
[Desktop Entry]
Icon=firefox
...
EOF

To specify your own icon, provide the full path to the icon graphics file (commonly .png or .svg format) after Icon=.

Look here and in other posts on this site, or look on the web or study some examples of .desktop files under /usr/share/applications to see how a .desktop shortcut file is formatted.

vanadium
  • 88,010
0

Replacing 'xdotool key F5' with 'touch ~/Desktop/MyGame.desktop' fixed the desktop icon display issue.

register.sh

#!/bin/bash

cd /home/jah/MyGame

echo "[Desktop Entry]" > MyGame.desktop

echo "Name=MyGame" >> MyGame.desktop

echo "Type=Application" >> MyGame.desktop

echo "Categories=Game;" >> MyGame.desktop

echo "Terminal=false" >> MyGame.desktop

echo "Exec=/home/jah/MyGame/MyGame" >> MyGame.desktop

echo "Icon=/home/jah/MyGame/MyGame.png" >> MyGame.desktop

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

chmod 755 ~/.local/share/applications/MyGame.desktop

cp MyGame.desktop ~/Desktop

chmod 755 ~/Desktop/MyGame.desktop

gio set ~/Desktop/MyGame.desktop "metadata::trusted" yes

gio info ~/Desktop/MyGame.desktop >gioinfo.log

sleep 1

touch ~/Desktop/MyGame.desktop