Basic control of amarok2 through DBus in PHP – napping again.

Posted on June 3, 2009


For my productivity naps I used to let the amarok script weekalarm wake me up after a certain number of minutes. Unfortunately amarok2 doesn’t seem to work with the script anymore. So I was looking for another way to tell amarok to start playing after a certain amount of time.

So some Google research led me to remote controlling applications through DCOP which is the (old!) inter process communication system of KDE. I found out that amarok could be remote controlled using certain DCOP commands. A short


however showed that amarok was not listening to DCOP messages. For a good reason: DCOP was replaced by DBus in KDE4. Regarding DBus debugging d-feet worked well for me.

You can simply use the command line to send DBus messages. The command to let amarok start playing would like something like that:

dbus-send --type=method_call --dest=org.kde.amarok /Player org.freedesktop.MediaPlayer.Play

I was looking further for a native programming language implementation of DBus.

After some (installation!) problems with the ruby library rbus I switched to PHP using Gree Labs PHP DBus. They also have a short tutorial which is a nice start on the matter.

Little tweek of the example code lets amarok start playing after a given number of minutes and increasing the volume continuously:


function execute($command, $args, $dbus) {
	if($args !== null) {

$minutes = intval($argv[1]);
sleep($minutes * 60);

$dbus = dbus_bus_get($type);

execute("VolumeSet", $START_VOLUME, $dbus);
execute("Play", null, $dbus);

for($count = $START_VOLUME + $VOLUME_STEP; $count < 100; $count += $VOLUME_STEP) {
	execute("VolumeSet", $count, $dbus);

Amarok is following the MPRIS specification, so for reading on more commands I can recommend the MPRIS specs.

Update: More command line dbus commands for amarok can be found here.

Tagged: , , ,
Posted in: Uncategorized