如何使用 bash 持续监控节奏盒的曲目变化
我想做同样的事情 这里,但是使用 shell 脚本(最好是在 bash 中)而不是 python。似乎使用 dbus-monitor 应该可以实现这样的事情,但我对 dbus 不太熟悉,而且我不清楚如何采用 python 问题的解决方案中描述的概念并将它们应用到 dbus-monitor 工具中。
I'd like to do the same thing as is described here, but using shell scripting (preferably in bash) instead of python. It seems like such a thing should be possible using dbus-monitor
, but I'm not very familiar with dbus, and it's not clear to me how to take the concepts described in the solution to the python question and apply them to the dbus-monitor tool.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我能找到的最简单的方法:
它产生这样的输出:
它还在启动时打印当前播放的歌曲。如果这不是您想要的,请查看
$line
的内容,看看它是否包含NameAcquired
或playingUriChanged
。如果它包含NameAcquired
,请跳过它。Python版本和bash版本的主要区别在于Python版本使用DBus来获取播放歌曲信息。我找不到使用 bash 执行此操作的好方法,但 rhythmbox-client --print-playing 似乎效果很好。
Here's the simplest way I could find:
It produces output like this:
It also prints the currently playing song when started up. If that is not what you want, look at the contents of
$line
and see if it containsNameAcquired
orplayingUriChanged
. If it containsNameAcquired
, skip it.The main difference between the Python version and this bash version is that the Python version uses DBus to get the playing song information. I couldn't find a good way to do that using bash, but
rhythmbox-client --print-playing
seems to work well.