Scripting always fascinates me. The thing i like about scripting is the ease with which you can get do something. The final code looks really neat and simple. Though scripting is cool, its needless to say that it has its own drawbacks. Nevertheless it is fun to write scripts to solve some simple problems.
We usually associate scripting with command line interface. But in the realm of GUIs and desktops we can think of different kind of scripting - the "Higher-level scripting". Higher-level scripting involves use of some protocols, like CORBA or DCOP, to interact with high level applications. CORBA (Common Object Request Broker Architecture) is an old classic example of interoperability protocol, which could be implemented to communicate between different applications. But CORBA implementations are usually slow, to be accepted for inter-application non-network communications. So KDE devised DCOP.
DCOP (Desktop Communication Protocol) is a simple protocol used for communication between various KDE applications. DCOP is a simple IPC/RPC mechanism built to operate over sockets. At a high level a KDE application registers with the dcop server, exposing some interface methods. Then inter-application communication is done through the dcop server by passing data in the form of serialised qt objects. KDCOP is a very simple graphical dcop browser and client. There is also a console dcop client called 'dcop'.
To demonstrate the use of the console dcop client i have written a trivial mashup script "Speak Clipboard". As its name says it speaks the contents of the clipboard. To use it just select some text in a browser (or any application) and then run the script to listen to the selected text. For easy access, you can create a shortcut and place it on your desktop sidebar.
The code of "Speak Clipboard" is...
#!/bin/bash
if [[ $1 = "stop" ]]
then
dcop ksayit ksayit dcopStop
exit
fi
message=`dcop klipper klipper getClipboardContents`
dcop ksayit ksayit dcopSayText "$message"
In the above script I have used KSayIt, a text to speech front for KDE. KTTS (KDE Text to Speech) is a subsystem within the KDE desktop for conversion of text to audible speech. Text to speech configurations can be done in KDE using KTTSMgr application. It enables setting up various text-to-speech systems like 'festival'.
The example given is very trivial and may be done directly using already existing KDE apps. However we can create really cool KDE mashups using dcop. Just as REST (Representational State Transfer) is fueling the web-mashups, dcop can be used for building their desktop counterparts.
Useful Links:
DCOP: Desktop COmmunications Protocol
Higher-level Scripting
KTTS - KDE Text-to-Speech System
Festival Speech synthesis system
Article on festival
Building Web Services the REST Way