The tilde doesn't get expanded in .pam_environment
the way it would in a profile script, and desktop files don't do shell expansion on their Exec
lines the way the shell would, so it's looking for a file that's literally named ~/usr/bin/eclipse
, which of course doesn't exist.
Replace the tilde in the PATH assignment with ${HOME} and it seems to work.
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
It seems there a line in the
.desktop
file that I was missing. In particular, the crucial line seems to be:More info on that here: What represent the StartupWMClass field of a .desktop file?
So, I have found what works for me below:
The steps I took to get this working are:
Use a text editor to create
eclipse.desktop
, and paste the above into itMove
eclipse.desktop
into~/.local/share/applications
Allow it to be executable:
chmod +x eclipse.desktop
Double-click
eclipse.desktop
which should appear in Nautilus asEclipse
In Unity launcher, right-click and select "Lock to Launcher"