I actually made a script for that. It places the icon down in the launcher, but with a minor change, you can put it at the top (or any other position) as well.
As it is, it is in python2, but simply change the shebang to #!/usr/bin/env python3
if you'd like to use it as python3. The code is identical.
To use it, the .desktop file needs to be in either /usr/share/applications
or in ~/.local/share/applications
, but usually that is the case.
How to use
- copy the script below, save it as
launcher_add.py
- make it executable
Run it by the command:
/path/to/launcher_add.py name_of_desktopfile.desktop
you have to use the filename of the .desktop file, without the path.
The script
#!/usr/bin/env python
import subprocess
import sys
desktopfile = sys.argv[1]
def current_launcher():
get_current = subprocess.check_output(["gsettings", "get", "com.canonical.Unity.Launcher", "favorites"]).decode("utf-8")
return eval(get_current)
def add_new(desktopfile):
curr_launcher = current_launcher()
last = [i for i, x in enumerate(curr_launcher) if x.startswith("application://")][-1]
new_icon = "application://"+desktopfile
if not new_icon in curr_launcher:
curr_launcher.insert(last, new_icon)
subprocess.Popen(["gsettings", "set", "com.canonical.Unity.Launcher","favorites",str(curr_launcher)])
else:
pass
add_new(desktopfile)
The script prevents multiple occasions in the launcher list of the same application, which would cause corruption of he list.
You can obtain a list of packages that think they own files in the directory using dpkg -S
e.g.:
dpkg -S /usr/share/applications
Then re-install each one:
sudo apt install --reinstall <package>
There are ways to automate that by processing the dpkg output - but doing it by hand will be a reminder to be more careful.
Best Answer
Keep the launcher sorted alphabetically
Running the script below in the background (see further below how to do that) will keep your launcher sorted alphabetically from a to z:
The top three launcher items before running the script: Gnome-terminal, Virtualbox, LibreOffice
Running the script: dconf-editor, Files, Firefox
What the script does
The (interface-) names of the applications is defined in
.desktop
files. These files can be stored in either/usr/share/applications
or~/.local/share/applications
. The latter "overrules" the global one, if the local one exists.The script checks for changes in the launcher list, running (in a loop, every two seconds) the command:
This returns a list of launcher items, ordered like the current order of the launcher.
If the launcher changes (e.g. if you add a new launcher), the script looks up the referring interface names in the
.desktop
files (preserving the precedence of the local.desktop
files) and sorts the launcher items, according to these interface-names.Subsequently, the script sets the sorted launcher by the command:
How to use
sort_launcher.py
Test-run it by running (in a terminal) the command:
If it works fine, add it to your startup applications: Dash > Startup Applications > Add the command:
The script
Notes
cpu 0%
, which means the script adds practically nothing to the processor load.