Ubuntu – How to stop partition icons in Unity launcher

gpartedlauncherunity

New problem. Ubuntu 16.04/16.10. Now, whenever I start gparted, new disk partition icons appear, just above the trash can icon, in the Unity launcher. I have to "unlock from launcher" to get rid of them.

Older posts for older versions of Ubuntu propose various fixes that no longer apply in 16.04/16.10. Any ideas of how to permanently get rid of these pesky icons?

Here's a screenshot that shows the 3 icons, just above the trash can icon:

enter image description here

Best Answer

The cause

Removing devices from the launcher will blacklist the device in the (gsettings) key

com.canonical.Unity.Devices blacklist

However, if the device is removed (disconnected in any way), the device is also removed from the blacklist. On next time you connect the device, the story starts over again.

The solution

The solution below will store blacklisted devices in a file. After removing them once, the device will never show up again in the launcher. If you disconnect a device, the script will immediately (re-) add the device as blacklisted.

#!/usr/bin/env python3
import subprocess
import time
import os

key = "com.canonical.Unity.Devices"
bl_file = os.environ["HOME"]+"/.blacklist_data"

while True:
    time.sleep(2)

    current = subprocess.check_output([
        "gsettings", "get", key, "blacklist",
        ]).decode("utf-8")
    if "@as" in current:
        current = []
    else:
        current = eval(current)        
    try:
        r = open(bl_file).read()
        r = [] if r == '' else r.splitlines()           
    except FileNotFoundError:
        r = []
    if current != r:
        newlist = list(set([d for d in current+r if not d == '']))
        open(bl_file, "wt").write("\n".join(newlist))
        subprocess.Popen(["gsettings", "set", key, "blacklist", str(newlist)])

How to use

  1. Copy the script into an empty file
  2. Save it as remember_blacklist.py
  3. Test- run it by the command:

    python3 /path/to/remember_blacklist.py
    
  4. If all works fine, add to Startup Applications: Dash > Startup Applications > Add. Add the command:

    python3 /path/to/remember_blacklist.py
    

Note

  1. Reading from gsettings (practically all what the script does) is extremely light-weight, and won't add any noticeable burden to your system
  2. If (and a long as) the device is opened in any nautilus window, it will still show up in the launcher. The icon will however not be locked to the launcher, and disappear.