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.
Asked
Active
Viewed 5,210 times
6
1 Answers
18
Here's the simplest way I could find:
#!/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
It produces output like this:
Now playing: Daft Punk - Overture
Now playing: Daft Punk - The Grid
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 contains NameAcquired
or playingUriChanged
. If it contains NameAcquired
, 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.

Mikel
- 24,855
- 8
- 65
- 66
-
If I don't want to monitor continuously; If I want to exit/kill the script after I close Rhythmbox, How do I do it? Is it possible within the script or do I need a separate script for that? – Khurshid Alam Aug 15 '16 at 18:59
-
You can do a 'break' in the loop after the rhythmbox command to continue to what's after the loop, Khurshid. – Dominic Hayes May 09 '19 at 18:09
-
Vyacheslav, did you put `#!/bin/bash` as the first line? – Mikel Jul 05 '19 at 13:35
-
Also note the other comment: `rhythmbox-client` doesn't exist on newer systems. – Mikel Jul 05 '19 at 13:36