I was reading and trying many things and then I found https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles which explains everything. Based on that, here comes a self-answer.
In this answer, I will demonstrate:
- how to display a program shortcut's details
- how to modify a program shortcut
- how to create a new program shortcut that runs a command
- how to add a program shortcut to some place so that it appears in Launcher Search (By Launcher Search, I mean the search interface that shows up when you click on Dash home icon on the left right, or by pressing the Windows key.)
- Familiarity with the commands cd and ls
Open Terminal. Cd to /usr/share/applications and display the folder's contents with ls, also display the folder with default file browser using xdg-open:
xdg-open . &
ls shows files with
.desktop extension. These files are text files and their contents can be viewed with gedit, for example by entering:
gedit gcalctool.desktop &
.desktop file in the folder is a program shortcut and the file browser displays them as program shortcuts instead of displaying their actual file-names. Which program shortcuts belong to which files can be discovered with grep: for example to find out what file is for Character Map, enter:
grep -Fi 'character map' *.desktop
which will show that it corresponds to the file
In order to edit the shortcut, open it with gksudo gedit:
gksudo gedit gucharmap.desktop &
In order to create a new shortcut, for example to create a shortcut that runs the following command:
python -i -c 'from math import *'
gksudo gedit gcalctool.desktop my-calc.desktop &
gcalctool.desktop is the already existing shortcut file for Calculator, and
my-calc.desktop is a new file name that doesn't exist yet. Using gedit, copy contents of
my-calc.desktop and then modify contents of
my-calc.desktop, and save.
contents of gcalctool.desktop:
Comment=Perform arithmetic, scientific or financial calculations
contents of my-calc.desktop (changed fields: Name, Comment, Exec, Terminal):
Comment=Perform calculations with Python
Exec=python -i -c 'from math import *'
Now 'My Calculator' icon should appear in the file browser window opened with
xdg-open .. Double clicking on it should open a terminal window with
python -i -c 'from math import *' ran. You can also run it from Launcher Search by searching for 'My Calculator'. You can drag the icon (in the file browser window) to an empty spot in launcher bar on the left (the taskbar) to have it there. If you drag the icon to Desktop, Ubuntu will say
Error while moving "my-calc.desktop" ... Error moving file: Permission denied.
Instead, press Alt while dragging it to Desktop, Ubuntu will display a menu: 'Move here', 'Copy here' and 'Link here', select 'Copy here', the shortcut will be copied to Desktop.
In order to be able to delete a shortcut in /usr/share/applications, enter:
gksudo xdg-open /usr/share/applications &
It's probably good to only delete shortcuts you've made and leave others intact.
If you can't find something in
/usr/share/applications and yet it appears from Launcher Search, it's probably in