Remove VLC player from sound menu in Unity bar

8,251

Solution 1

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.

Solution 2

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 here enter 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)

Solution 3

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 here enter 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)

Solution 4

Ubuntu 14.04 simple solution (only one command, no sudo, no script).

Open Terminal application, then copy, paste and execute one of the following command. After that the sound indicator will be automatically cleaned out after VLC exits.

  1. don't leave any entry within the sound indicator:

    (mkdir -p ~/.local/share/applications);(cp /usr/share/applications/vlc.desktop ~/.local/share/applications);(sed -i 's/Exec=\/usr\/bin\/vlc --started-from-file %U/Exec=sh -c "\/usr\/bin\/vlc --started-from-file %U; gsettings reset com.canonical.indicator.sound interested-media-players"/' ~/.local/share/applications/vlc.desktop)
    
  2. leave Rhythmbox entry within the sound indicator:

    (mkdir -p ~/.local/share/applications);(cp /usr/share/applications/vlc.desktop ~/.local/share/applications);(sed -i 's/Exec=\/usr\/bin\/vlc --started-from-file %U/Exec=sh -c "\/usr\/bin\/vlc --started-from-file %U; gsettings set com.canonical.indicator.sound interested-media-players \\\"['\'rhythmbox.desktop\'']\\\""/' ~/.local/share/applications/vlc.desktop)
    
  3. undo changes:

    rm ~/.local/share/applications/vlc.desktop
    
Share:
8,251

Related videos on Youtube

Nick Bailuc
Author by

Nick Bailuc

I have been messing with Linux since I was 10 years old. I plan to become a programmer. I am interested in many related Open Source projects. I have multiple years of experience in AMD proprietary driver "fglrx" and its command "amdconfig". I am the administrator of a project called HL:Exp Mobile. We are a team who are porting Half-Life: Opposing Force and Half-Life: Blue Shift to Unity3D engine and make it run on mobile phones. (Find us on moddb or Facebook). I am also interested in projects like The Zeitgeist Movement and The Venus Project. I hope to meet Linus Torvalds some day.

Updated on September 18, 2022

Comments

  • Nick Bailuc
    Nick Bailuc almost 2 years

    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.

    • Fern Moss
      Fern Moss about 10 years
      I asked this question before, so this is sort of a duplicate. Although this asks just about removing VLC from the sound menu, versus stopping it from continually appearing. Not sure if both answers should stay open. askubuntu.com/questions/455940/…
    • Exeleration-G
      Exeleration-G over 8 years
      Possible duplicate: askubuntu.com/questions/177652/disable-vlcs-mpris-plugian
  • Nick Bailuc
    Nick Bailuc about 10 years
    I did the terminal method because I didnt want to install unneeded applications. thank you, it worked instantly
  • Jacob Vlijm
    Jacob Vlijm about 10 years
    I agree! if not necessary, I'd prefer not to install addition software. Glad it worked out.
  • Fern Moss
    Fern Moss about 10 years
    But it will be readded as soon as you open VLC again...
  • Fern Moss
    Fern Moss about 10 years
    Correction: as soon as you start playing a video in VLC again.
  • Jacob Vlijm
    Jacob Vlijm about 10 years
    @AibaraIduas edited my anser.
  • Fern Moss
    Fern Moss about 10 years
    This option is no longer present in VLC.
  • Hedwig
    Hedwig about 10 years
    D'oh it exists for me, perhaps i've an old version ..
  • Nick Bailuc
    Nick Bailuc about 10 years
    excellent, the script worked exactly as it was suppose to
  • Nick Bailuc
    Nick Bailuc about 10 years
    i didnt check last time, but double clicking on a audio or video file opens vlc but does not open the file. i have to go to vlc and select "open from" which is very annoying. can you help out?
  • Jacob Vlijm
    Jacob Vlijm about 10 years
    @NickBailuc I tried, and you are right, I will get back to you on this!
  • Nick Bailuc
    Nick Bailuc about 10 years
    you know what i dont mean to upset you but i tried Sneetsher's solution and it worked, sorry but once again thanks for all the effort you put into this
  • Jacob Vlijm
    Jacob Vlijm about 10 years
    On the contratry, if it works better for your purpose, you should accept Sneetsher's answer. I still want to solve it though. Just for me, but also because the similar question of @AibaraIduas prefers to have VLC in the menu if it runs.
  • Lilley
    Lilley over 9 years
    Yes it works, but running a check every 10 secondes for an event that may happen once or twice per session seems extremely inefficient.
  • Jacob Vlijm
    Jacob Vlijm over 9 years
    @Lilley getting values from gsettings is extremely light, and be aware of the fact that the system runs all kinds of loops constantly.
  • jessexknight
    jessexknight over 3 years
    It's not clear whether 1 & 2 are two solution options or two steps to the same solution.
  • user.dz
    user.dz over 3 years
    @jessexknight they are 2 steps.