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.
Best Answer
You need to add
as the first line to your file.
And just in case: Make sure that the file name ends with
.desktop
And also make sure you have made it executable.