从 Unity 栏中的声音菜单中删除 VLC 播放器

从 Unity 栏中的声音菜单中删除 VLC 播放器

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).

在此处输入图片描述

Sorry for giving a very low resolution image.

答案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.

答案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

在此处输入图片描述

  • 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.

在此处输入图片描述

  • Done, VLC disappeared from the menu.

在此处输入图片描述 在此处输入图片描述

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)

解决方案是将 VLC 从声音菜单中移除,但如果您启动 VLC,它将再次出现在声音菜单中。下面的脚本不会阻止这种情况,但会在 VLC 关闭后立即自动将其移除。

使用方法:

复制以下脚本,将其粘贴到空文本文件中,并将其另存为vlc,使其可执行。然后将文件vlc.desktop/usr/share/applications复制到并将以~/.local/share/applications开头的(第一)行替换为。注销并重新登录。桌面文件将重定向到脚本,脚本将启动 VLC 并等待它停止并立即从声音菜单中删除 VLC。Exec=Exec=/path/to/script/vlc

#!/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)

其他应用

此方法/脚本也可用于声音菜单中的其他应用程序。然后,根据其他应用程序,需要更改脚本最后一节中的两行:

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

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

答案3

仅当用户定义的应用程序运行时才在声音菜单中显示它们

以下解决方案可灵活地同时用于在声音菜单中占据一席之地的多个应用程序。用户可以定义(和更改)哪些应用程序在菜单中具有永久位置,哪些应用程序在关闭后应从声音菜单中删除。

在此处输入图片描述 在此处输入图片描述

它是什么以及它做什么

解决方案是使用一个从启动(登录)开始运行的脚本。它允许用户定义的应用程序出现在声音菜单中,但在关闭后会从声音菜单中删除这些应用程序。

该脚本对桌面文件的功能没有影响。我没有注意到对处理器负载有任何影响,内存使用量可以忽略不计。

如何使用

  • 将以下脚本复制到一个空文件中,并将其另存为cleanup_soundmenu.py

  • 在以 开头的行中no_show =,设置了关闭后应从菜单中清除的应用程序。设置了两个示例:['rhythmbox', 'vlc']。名称来自其桌面文件,从 中删除.desktop

  • 在以 开头的行中cleanup_interval,用户可以定义清理检查之间的间隔。默认情况下为 10 秒。

  • 将以下行添加到Startup Applications(Dash > 启动应用程序 > 添加):

    python3 /path/to/cleanup_soundmenu.py
    

下次登录时,如果定义的应用程序未运行,则会从声音菜单中清除。

剧本

#!/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)

答案4

这是一个文章关于如何添加此功能做相反的场景:

工具 -> 首选项 -> 全部 -> 接口 -> 控制接口 -> D-Bus 控制接口

相关内容