从Unity工具栏的声音菜单中移除VLC播放器。

我不常使用VLC,所以我想把它从右上角的声音菜单中移除。我找到了一张小图片来展示它的样子(声音菜单已打开,显示了VLC和其他音乐播放器)。

enter image description here

抱歉提供了一张非常低分辨率的图片。

我之前问过这个问题,所以这有点重复了。尽管这只是询问如何从声音菜单中删除VLC,而不是阻止它不断出现。不确定两个答案是否都应该保持开放状态。https://askubuntu.com/questions/455940/prevent-vlc-from-always-showing-in-the-sound-indicator - Fern Moss
尼克,我编辑了我的答案以防止它(永久地)返回到声音菜单。 - Jacob Vlijm
是的,每当我使用VLC时它总是出现。我正在通过互联网教程寻找如何在首选项中禁用它,但由于我的版本太新,所以找不到它。它被称为“D-Bus”。 - Nick Bailuc
可能是重复问题:askubuntu.com/questions/177652/disable-vlcs-mpris-plugian - Exeleration-G
5个回答

要在声音菜单中禁用VLC,请按照以下步骤操作:
  1. 移动VLC DBus插件

    sudo mv /usr/lib/vlc/plugins/control/libdbus_plugin.so /usr/lib/vlc/plugins/control/libdbus_plugin.so.backup
    
  2. 打开dconf-editor,从以下位置删除vlc.desktop

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

    或者通过终端重置:

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

注意:某些人可能喜欢修改声音指示器菜单,以隐藏非活动播放器的控件或在关闭后删除。换句话说,正在运行的播放器具有完全的控制,关闭的播放器只有启动程序(没有控制按钮),或者完全从菜单中消失。


3这个修复方法也有效! - Fern Moss
不清楚1和2是两个解决方案选项还是达到同一个解决方案的两个步骤。 - jessexknight
1@jessexknight 他们有两个步骤。 - user.dz

如何从声音菜单中移除VLC / 如何防止VLC重新出现在声音菜单中。
从声音菜单中移除VLC
GUI方法
- 安装dconf编辑器 - 打开dconf编辑器,并浏览到:com/canonical/indicator/sound

enter image description here

在声音菜单(interested-media-players)项目列表中,删除您不需要/不想在菜单中显示的应用程序。关闭dconf编辑器。

enter image description here

完成了,VLC从菜单中消失了。

enter image description here enter image description here

命令行方法
要查看当前的菜单项,运行以下命令: gsettings get com.canonical.indicator.sound interested-media-players
它会输出如下内容: ['rhythmbox.desktop', 'vlc.desktop']
要移除VLC,从列表中删除“vlc.desktop”,并通过以下命令应用更改后的菜单: gsettings set com.canonical.indicator.sound interested-media-players "['rhythmbox.desktop']"

防止VLC在声音菜单中重新出现(14.04)

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

使用方法:

复制下面的脚本,粘贴到一个空的文本文件中,并将其保存为vlc,使其可执行。然后将/usr/share/applications目录中的vlc.desktop文件复制到~/.local/share/applications,并将以Exec=开头的(第一行)替换为Exec=/path/to/script/vlc。退出并重新登录。桌面文件将被重定向到脚本,脚本将启动VLC并等待其停止,并立即从声音菜单中移除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)

我选择了终端方法,因为我不想安装不必要的应用程序。谢谢,它立即生效了。 - Nick Bailuc
1我同意!如果不是必要的话,我宁愿不安装额外的软件。很高兴问题解决了。 - Jacob Vlijm
但只要您再次打开VLC,它就会被重新添加进来... - Fern Moss
更正:一旦您再次开始在VLC中播放视频。 - Fern Moss
@AibaraIduas修改了我的答案。 - Jacob Vlijm
太棒了,脚本完全按照预期的方式运行。 - Nick Bailuc
上次我没有检查,但是双击音频或视频文件会打开VLC,但不会打开文件。我必须去VLC并选择“从中打开”,这非常烦人。你能帮忙解决吗? - Nick Bailuc
1@NickBailuc 我试过了,你说得对,我会给你回复的! - Jacob Vlijm
你知道我不是故意惹你生气的,但我试了Sneetsher的解决方案,它起作用了。对不起,再次感谢你为此付出的努力。 - Nick Bailuc
相反地,如果這對你的目的更好,你應該接受Sneetsher的答案。儘管如此,我仍然想解決這個問題。不僅是為了我自己,還因為AibaraIduas提出的類似問題希望在運行時在菜單中有VLC。 - Jacob Vlijm

Ubuntu 14.04简单解决方案(只需一个命令,无需sudo,无需脚本)。

打开终端应用程序,然后复制、粘贴并执行以下命令之一。之后,当VLC退出后,声音指示器将自动清除。

不要在声音指示器中留下任何条目: (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)
在声音指示器中保留Rhythmbox条目: (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)
撤销更改: rm ~/.local/share/applications/vlc.desktop

只在运行时在声音菜单中显示用户定义的应用程序。
下面的解决方案可以灵活地同时适用于多个应用程序,并在声音菜单中占据一个位置。用户可以定义(并更改)哪些应用程序在菜单中有一个固定的位置,哪些应用程序在关闭后应该从声音菜单中移除。

enter image description here enter image description here

是什么以及它的功能

该解决方案由一个从启动(登录)运行的脚本组成。它允许用户定义的应用程序出现在声音菜单中,但在这些应用程序关闭后将其从声音菜单中移除。

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

如何使用

  • 将下面的脚本复制到一个空文件中,保存为cleanup_soundmenu.py

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

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

  • 将以下行添加到启动应用程序(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)

是的,它可以工作,但每10秒运行一次检查,而这个事件可能在整个会话中只发生一两次,似乎非常低效。 - Lilley
@Lilley 从gsettings获取值非常轻量级,并且要意识到系统会不断运行各种循环。 - Jacob Vlijm

这是一篇关于如何添加此功能以执行相反情景的文章:
工具 -> 首选项 -> 所有 -> 接口 -> 控制接口 -> D-Bus控制接口

3这个选项在VLC中已经不再存在了。 - Fern Moss
糟糕,对我来说确实存在,可能是因为我使用的是旧版本.. - Hedwig