Unlocking applications from launcher from the command line

Solution 1:

The command to get the current launcher's icons is:

gsettings get com.canonical.Unity.Launcher favorites

This will give you a list like:

['item_1', 'item_2', 'application://application_to_remove.desktop', 'etc']

If you remove your item from the list and set the altered version of the list by the command:

gsettings set com.canonical.Unity.Launcher favorites "['item_1', 'item_2', 'etc']"
(mind the double quotes)

Your application is unlocked from the launcher.

Example script

As an example of how the job can be done by a (python) script:

#!/usr/bin/env python3
import subprocess
import sys

key = "com.canonical.Unity.Launcher"
desktopfile = sys.argv[1]

curr_launcher = eval(subprocess.check_output([
    "gsettings", "get", key, "favorites"
    ]).decode("utf-8"))
new_launcher = [item for item in curr_launcher if not desktopfile in item] 
subprocess.Popen(["gsettings", "set", key,"favorites",str(new_launcher)])

How to use

  • Paste the script into an empty file, save it as remove_fromlauncher.py
  • Run it by the command

    python3 /path/to/remove_fromlauncher.py <application.desktop>
    

    or shorter:

    python3 /path/to/remove_fromlauncher.py <application>
    

    Example remove Virtualbox:

    python3 /path/to/remove_fromlauncher.py virtualbox.desktop
    

Note

Keep in mind that you cannot simply remove all items from the list; It also includes items which are not applications.


EDIT

Version of the script to remove multiple icons at once:

#!/usr/bin/env python3
import subprocess
import sys

key = "com.canonical.Unity.Launcher"

desktopfiles = sys.argv[1:]

for desktopfile in desktopfiles:
    curr_launcher = eval(subprocess.check_output([
        "gsettings", "get", key, "favorites"
        ]).decode("utf-8"))
    new_launcher = [item for item in curr_launcher if not desktopfile in item] 
    subprocess.Popen(["gsettings", "set", key,"favorites",str(new_launcher)])

Usage is pretty much the same, but now you can use multiple argumnents at once, e.g.:

python3 /path/to/remove_fromlauncher.py gedit thunderbird

will remove both Thunderbird and Gedit from the launcher.