Ubuntu – How to permanently unlock partitions from launcher in 16.04

command linedevicesgsettingslauncherunlock

I tried to unlock partitions from the launcher, but they keeps reappearing after every reboot. Is there any good way to permanently remove partitions from the launcher?

This is happening only on Ubuntu 16.04

enter image description here

Best Answer

Although the solution below is not a fix to what seems to be a minor bug, you can use it as a workaround to automatically blacklist devices on startup (log in).

The solution

...is a small script that remembers your blacklisted items on log in. It runs with two arguments: get and set. The first is to read the current blacklisted items, the second will (re-) set the list to the last read version.

In practice

  • Remove the devices from the Unity Launcher like you are used to.
  • Run the command /path/to/remember_blacklist.sh get This will make a snapshot of the currently blacklisted devices.

Now the next time you log in or restart, the blacklisted devices are automatically removed. Of course you can add the command to a shortcut.

How to use / set up

  • Copy the script below into an empty file, save it as remember_blacklist.sh

    #!/bin/bash
    
    arg=$1
    blacklist=~/.currblacklist
    key="com.canonical.Unity.Devices blacklist"
    
    if [ "$arg" == "get" ]
    then
     printf "$(gsettings get $key)" > $blacklist
    elif [ "$arg" == "set" ]
    then
      if [ "$(cat $blacklist)" == "@as" ]
      then 
        gsettings set $key []
      else
        gsettings set $key "$(cat $blacklist)"
      fi
    fi
    
  • make it executable (!)

  • Add the following to Startup Applications Dash > Startup Applications > Add. Add the command

    /bin/bash -c "sleep 10 && /path/to/remember_blacklist.sh set"
    
  • Remove the devices from the launcher as usual
  • To remember, run: /path/to/remember_blacklist.sh get

Explanation

If you remove a device from the launcher, it is blacklisted. You can read the current list of blacklisted devices with the command:

gsettings get com.canonical.Unity.Devices blacklist

This will output something like

['0A444ED409660B91-intern_1', '2899FAA548C61099-intern_2']

What the script does is:

  • when run with the argument get: it reads the current blacklist and saves the output in a hidden file: ~/.currblacklist
  • when run with the argument set: it reads the content of the file ~/.currblacklist and sets the blaclist with the command:

    gsettings set com.canonical.Unity.Devices blacklist <content_of_the_file>