Welcome, guest | Sign In | My Account | Store | Cart

This recipe shows how to interact with DCOP services using Python.

Python, 20 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
import pydcop

try:
    # get 'player' service of 'amarok' aplication
    playerService = pydcop.DCOPObject('amarok', 'player')

    # call service methods for getting song information
    info = dict(
        title=playerService.title(),
        artist=playerService.artist(),
        album=playerService.album()
    )

    print '%(artist)s - %(title)s (%(album)s)' % info

except RuntimeError, e:
    print 'Amarok is not running.'

# sample output:
# Mercyful Fate - A Dangerous Meeting (Don't Break The Oath)

DCOP is an interprocess communication system for KDE versions up to 4 (which replaced it with D-Bus), for more information, see: DCOP on Wikipedia. It is not usable for KDE 4, so it is a pretty dead technology; but this recipe could be useful for people who are still using KDE 3.5.

The code for this recipe displays the title, artist and the album of the currently playing song by Amarok 1.x via Amarok's player service.

You need to install python bindings for DCOP to be able to use the code; on Debian the package you need is python-dcop.

The recipe can be extended in many ways by calling other methods of Amarok's player service, or adapted to work with other KDE applications; you can use kdcop application to discover applications and their DCOP services.

Created by Yuce Tekol on Thu, 13 Aug 2009 (MIT)
Python recipes (4591)
Yuce Tekol's recipes (2)

Required Modules

Other Information and Tasks