Mik*_*kel 15
这是我能找到的最简单的方法:
#!/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并查看它是否包含NameAcquired或playingUriChanged.如果包含NameAcquired,请跳过它.
Python版本和这个bash版本之间的主要区别在于Python版本使用DBus来获取播放歌曲信息.我找不到使用bash做到这一点的好方法,但rhythmbox-client --print-playing似乎运作良好.