【问题标题】:How to continuously monitor rhythmbox for track change using bash如何使用 bash 持续监控节奏盒的音轨变化
【发布时间】:2011-07-17 16:39:57
【问题描述】:

我想做与here 中描述的相同的事情,但使用 shell 脚本(最好在 bash 中)而不是 python。使用dbus-monitor似乎应该可以实现这样的事情,但我对dbus不是很熟悉,我不清楚如何将解决方案中描述的概念应用于python问题并将它们应用于dbus-监控工具。

【问题讨论】:

    标签: bash dbus rhythmbox


    【解决方案1】:

    这是我能找到的最简单的方法:

    #!/bin/bash
    
    interface=org.gnome.Rhythmbox.Player
    member=playingUriChanged
    
    # listen for playingUriChanged DBus events,
    # each time we enter the loop, we just got an event
    # so handle the event, e.g. by printing the artist and title
    # see rhythmbox-client --print-playing-format for more output options
    
    dbus-monitor --profile "interface='$interface',member='$member'" |
    while read -r line; do
        printf "Now playing: "
        rhythmbox-client --print-playing
    done
    

    它产生这样的输出:

    Now playing: Daft Punk - Overture
    Now playing: Daft Punk - The Grid
    

    它还会在启动时打印当前播放的歌曲。如果这不是您想要的,请查看$line 的内容,看看它是否包含NameAcquiredplayingUriChanged。如果它包含NameAcquired,请跳过它。

    Python版本和这个bash版本的主要区别在于Python版本使用DBus来获取播放歌曲信息。我找不到使用 bash 的好方法,但 rhythmbox-client --print-playing 似乎效果很好。

    【讨论】:

    • 如果我不想连续监控;如果我想在关闭 Rhythmbox 后退出/终止脚本,我该怎么做?是否可以在脚本中使用,还是我需要一个单独的脚本?
    • 你可以在节奏盒命令之后在循环中做一个“中断”以继续循环之后的内容,Khurshid。
    • 维亚切斯拉夫,你把#!/bin/bash放在第一行了吗?
    • 另请注意另一条评论:rhythmbox-client 在较新的系统上不存在。
    猜你喜欢
    • 2014-07-09
    • 2019-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-08
    • 2011-06-07
    相关资源
    最近更新 更多