The most elegant way is to "restart" the icon; to remove the icon from its position in the launcher and replace it on the same position. The script below does the job. It is in python2, since 12.04 does not come with python3 by default. However, it can be used in python3 as well, only change the shebang in that case. The script can also be useful (on later Ubuntu versions as well) to immediately apply a changed icon for example.
You can simply use it by calling the script, with the edited desktop file as an argument (see further below).
Note: in 12.04, if a refreshed icon represents a running application, the application in question will crash, as described in this question, so if you use it, make sure the application is not running. In 14.04, the icon will simply not refresh in case of a running application.
The script
#!/usr/bin/env python
import subprocess
import time
import sys
desktopfile = sys.argv[-1]
def read_currentlauncher():
# reads the current launcher contents
get_launcheritems = subprocess.Popen([
"gsettings", "get", "com.canonical.Unity.Launcher", "favorites"
], stdout=subprocess.PIPE)
return get_launcheritems.communicate()[0].decode("utf-8")
def set_launcher(llist):
# sets a defined unity launcher list
current_launcher = str(llist).replace(", ", ",")
subprocess.Popen([
"gsettings", "set", "com.canonical.Unity.Launcher", "favorites",
current_launcher,
])
def refresh_icon(desktopfile):
current_launcher = read_currentlauncher()
current_launcher_temp = eval(current_launcher)
item = [item for item in current_launcher_temp if desktopfile in item][0]
index = current_launcher_temp.index(item)
current_launcher_temp.pop(index)
set_launcher(current_launcher_temp)
time.sleep(2)
set_launcher(current_launcher)
refresh_icon(desktopfile)
How to use it
If you really want to make it smooth
Make the script executable, remove the .py
extension, save it in ~/bin
. After log out/in, you can run it by the command:
refresh firefox.desktop (as an example)
unity --replace
works? I dont mind the reload of everything. – Noitidart Feb 02 '15 at 09:18unity --replace
works in ubuntu 16.04 but will not reload the heavy applications like Chrome, Thunderbirds... – PhatHV Oct 10 '16 at 02:14