Remove VLC player from sound menu in Unity bar

I don’t use VLC that much to have it there, so I would like to remove it from the sound menu in the top right. I found a small image to show what it looks like (the sound menu is open and shows VLC along with other music players).

enter image description here

Sorry for giving a very low resolution image.


To disable VLC in sound menu, follow the steps:

  1. Move VLC DBus plugin

     sudo mv /usr/lib/vlc/plugins/control/libdbus_plugin.so /usr/lib/vlc/plugins/control/libdbus_plugin.so.backup
    
  2. Open dconf-editor, Remove vlc.desktop from:

     /com/canonical/indicator/sound/interested-media-players
    

    Or just reset it through terminal

     dconf reset /com/canonical/indicator/sound/interested-media-players
    

Note: Someones may like to Modify sound indicator menu to hide controls from inactive player or remove it after closeing. In other words, Running players have full controls, Closed ones either only launcher (no control buttons) or disappear totally from menu.


How to remove VLC from the sound menu / How to prevent VLC from reappearing in the sound menu.

Removing VLC from the sound menu

GUI method

  • Install dconf editor
  • Open dconf-editor, and browse to: com/canonical/indicator/sound

enter image description here

  • In the list of soundmenu (interested-media-players) items, remove the application(s) you do not need / want to appear in the menu. Close the dconf-editor.

enter image description here

  • Done, VLC disappeared from the menu.

enter image description hereenter image description here

Command line method

  • To read the current menu items:

    gsettings get com.canonical.indicator.sound interested-media-players
    

    gives an output like:

    ['rhythmbox.desktop', 'vlc.desktop']
    
  • To remove VLC, remove vlc.desktop from the list and set the changed menu by the command:

    gsettings set com.canonical.indicator.sound interested-media-players "['rhythmbox.desktop']"
    

Preventing VLC from returning in the sound menu (14.04)

The solution removes VLC from the sound menu, but if you start VLC, it will appear again in the sound menu. The script below does not prevent that, but immediately and automatically removes it once VLC is closed.

To use it:

Copy the script below, paste it in an empty textfile and save it as vlc, make it executable. Then copy the vlc.desktop file from /usr/share/applications to ~/.local/share/applications and replace the (first) line starting with Exec= by Exec=/path/to/script/vlc. Log out and back in. The desktopfile will be redirected to the script, the script will start VLC and wait for it to stop and remove VLC from the soundmenu immediately.

#!/usr/bin/python3
import subprocess
import getpass
import time

curruser = getpass.getuser()

def read_currentmenu():
    # read the current launcher contents
    get_menuitems = subprocess.Popen([
        "gsettings", "get", "com.canonical.indicator.sound", "interested-media-players"
        ], stdout=subprocess.PIPE)
    return eval((get_menuitems.communicate()[0].decode("utf-8")))

def set_current_menu(current_list):
    # preparing subprocess command string
    current_list = str(current_list).replace(", ", ",")
    subprocess.Popen([
        "gsettings", "set", "com.canonical.indicator.sound", "interested-media-players",
        current_list,
        ])

subprocess.call(["/usr/bin/vlc"])                    
current_list = read_currentmenu()
for item in current_list:
    if item == "vlc.desktop":
        current_list.remove(item)
set_current_menu(current_list)

Other applications

This method / script can also be used for other applications in the sound menu. Two lines in the last section of the script need to be altered then, according to the other application:

if item == "vlc.desktop":  (change to desktop file of the application)

and

subprocess.call(["/usr/bin/vlc"]) (change the command to run the application)

Show user defined applications in the soundmenu only if they run

The solution below is flexibly usable for mutiple applications at once with a position in the sound menu. User can define (and change) which applications have a permanent position in the menu, and which ones should be removed from the sound menu after they are closed.

enter image description hereenter image description here

What it is and what it does

The solution exists of a script that runs from startup (login). It allows user defined applications to appear in the sound menu, but removes those applications from the soundmenu after they close.

The script has no effect on the functionality of the desktop files. I could not notice any effect on the processor load, memory usage is negligible.

how to use

  • Copy the script below into an empty file, save it as cleanup_soundmenu.py

  • In the line starting with no_show =, applications are set which should be cleaned up from the menu after they are closed. Two examples are set: ['rhythmbox', 'vlc']. The names are derrived from their desktop files, stripped from .desktop.

  • In the line, starting with cleanup_interval, user can define the interval between the clean up checks. By default it is 10 seconds.

  • Add the following line to Startup Applications (Dash > Startup Applications > Add):

    python3 /path/to/cleanup_soundmenu.py
    

On next login, defined application will be cleaned from sound menu if they are not running.

The script

#!/usr/bin/env python3

import subprocess
import time
import getpass

no_show = ['rhythmbox', 'vlc'] # add names here, to set apps not to show
cleanup_interval = 10 # cleanup interval (in seconds)

curruser = getpass.getuser()

def createlist_runningprocs():
    processesb = subprocess.Popen(
        ["ps", "-u", curruser],
        stdout=subprocess.PIPE)
    process_listb = (processesb.communicate()[0].decode("utf-8")).split("\n")
    return process_listb

def read_soundmenu():
    # read the current launcher contents
    get_menuitems = subprocess.Popen([
        "gsettings", "get",
        "com.canonical.indicator.sound",
        "interested-media-players"
        ], stdout=subprocess.PIPE)
    try:
        return eval(get_menuitems.communicate()[0].decode("utf-8"))
    except SyntaxError:
        return []

def set_soundmenu(new_list):
    # set the launcher contents
    subprocess.Popen([
        "gsettings", "set",
        "com.canonical.indicator.sound",
        "interested-media-players",
        str(new_list)])

def check_ifactionneeded():
    snd_items = read_soundmenu()
    procs = createlist_runningprocs()
    remove = [item+".desktop" for item in no_show if not item in str(procs)]
    if len(remove) != 0:
        for item in remove:
            try:
                snd_items.remove(item)
            except ValueError:
                pass
        return snd_items
    else:
        pass

while 1 != 0:
    new_list = check_ifactionneeded()
    if new_list != None:
        set_soundmenu(new_list)
    time.sleep(cleanup_interval)