Ubuntu – How to hide Empathy’s mail indicator icon
empathyindicator
Since I have configured Empathy, I have a new icon shown in the indicator icon bar. This icon remains visible even if I close Empathy.
How can I have this icon disappear when not using Empathy?
Best Answer
Inspired by cl-netbox' answer, you can automatically remove the icon after empathy closes. This can be done by running (starting) empathy through a wrapper script. As far as I can see, this has no downside. The only possible downside would be that the right- click option to open with does not work, but that does not apply to empathy.
The wrapper would only run during, and only as long as, empathy is running, waiting for it to close, so the solution is very specific.
What it does
When empathy is run (through the wrapper), a small script is started, doing two things:
look (check) for the empathy indicator to be visible, by the command:
gsettings get com.canonical.indicator.messages applications
This will return a list of current indicators. If the empathy indicator is not included, the script adds it to the list and sets the altered list by the command:
gsettings set com.canonical.indicator.messages applications <newlist>
Then the script looks for the existence of an empathy window
If no empathy window exists any more, the script fetches the list of indicators again and removes the indicator in the same way.
Then the wrapper- script terminates itself, and your icon is removed from the panel.
The wrapper
#!/usr/bin/env python3
import subprocess
import time
key = "com.canonical.indicator.messages"
def hide_icon(icon, mode):
# function to remove the targeted icon from the list
current = eval(subprocess.check_output([
"gsettings", "get", key, "applications"
]).decode("utf-8").strip())
if mode == "h":
try:
current.remove(icon)
except ValueError:
pass
elif mode == "s":
if not icon in current:
current.append(icon)
subprocess.call([
"gsettings", "set", key, "applications", str(current)
])
# run empathy
subprocess.Popen(["empathy"])
# make sure the icon shows
hide_icon('empathy.desktop', "s")
while True:
time.sleep(3)
try:
# get the pid of empathy
pid = subprocess.check_output(["pgrep", "empathy"]).decode("utf-8").strip()
except subprocess.CalledProcessError:
break
else:
try:
# see if the pid of empathy is still in the window list...
wlist = subprocess.check_output(["wmctrl", "-lp"]).decode("utf-8")
# ...if not, remove the icon from the list and break
if not pid in wlist:
hide_icon('empathy.desktop', "h")
break
except subprocess.CalledProcessError:
pass
How to set up
Copy the script into an empty file, save it as no_indicator.py
Test-run the script with the command:
python3 /path/to/no_indicator.py
The icon should disappear if you close empathy. If all works fine:
Copy the global empathy.desktop file to ~/.local/share/applications:
The new version of dropbox V1.0 and higher comes with a support for new application indicator. I downloaded this .deb file which automatically installs monochrome indicator icons for dropbox. Even if you update dropbox, the monochrome icons still remain unchanged.
You can download it by adding the following PPA to the repository through the command line (terminal) by typing,
You can remove the message indicator by removing the indicator-messages package by clicking on that link and clicking uninstall. Or by executing the following command in a terminal:
Best Answer
Inspired by cl-netbox' answer, you can automatically remove the icon after
empathy
closes. This can be done by running (starting)empathy
through a wrapper script. As far as I can see, this has no downside. The only possible downside would be that the right- click option to open with does not work, but that does not apply toempathy
.The wrapper would only run during, and only as long as, empathy is running, waiting for it to close, so the solution is very specific.
What it does
When empathy is run (through the wrapper), a small script is started, doing two things:
look (check) for the
empathy
indicator to be visible, by the command:This will return a list of current indicators. If the
empathy
indicator is not included, the script adds it to the list and sets the altered list by the command:Then the script looks for the existence of an
empathy
windowIf no empathy window exists any more, the script fetches the list of indicators again and removes the indicator in the same way.
The wrapper
How to set up
Copy the script into an empty file, save it as
no_indicator.py
Test-run the script with the command:
The icon should disappear if you close empathy. If all works fine:
Copy the global
empathy.desktop
file to~/.local/share/applications
:Open the locally copied file with
gedit
:replace the line:
by:
just before (above) the line, starting with
Actions=
, insert the line:This is to prevent an extra icon in the Launcher when you run
empathy
Log out and back in