Browsing dcop Functions in kdcop
A program called kdcop will show all the dcop accessible apps and what can be scripted. Think it as the dictionary, ala. Apple's AppleScript.
Click the + to expand the headings to see what signals can be sent via. dcop.
Open up Konqueror. Any app you want to communicate via. dcop must be running when you try to communicate to it.
Expand the Konqueror-#### (replace #### with process number of the running Konqueror you want to communicate to).
Expand the "KonquerorIface (Default)" item. (Default) means it's the default dcop interface, and when exploring programs in kdcop, that's probably what you want to check first.
You will now see all the functions you can access.
ASYNC openBrowserWindow(QString url) looks like it might be helpful. It's name hints that it would be used for opening a browser window with a new url -- such as http://imaclinux.net/.
Executing dcop commands in kdcop
You can either access the interface by selecting it kdcop, and double clicking on it or going to Execute -> Execute (Ctrl-X) menu item.
It will pop up a dialog that will let you put in an url in the "value" box, and will open that webpage.
That's neat. But you can't really use it in a shell, nor is really useful (as you could just as easily open konqueror by clicking it's icon, and typing the url into it's url bar.
Excuting dcop commands using dcop
Instead, you can use dcop command line program to do the exact same thing. The syntax for dcop is:
dcop [ application [object [function [arg1] [arg2] [arg3] ... ] ] ]
To do the exact same thing as shown above in kdcop exampling (opening a browser window with Konqueror to http://imaclinux.net/:
Command: | dcop | konqueror | KonquerorIface | openBrowserWindow | "http://imaclinux.net/" |
In kdcop: | konqueror-1233 | KonquerorIface | ASYNC openBrowserWindow(Qstring url) | ||
Description: | Application (pid optional) |
Interface | Function Second Word, Before ( |
Arguments - Quote Each If Neccessary (replace each comma with a space) |
Type that in a konsole or xterm, or put it in a script, and you will see a Konqueror window at http://imaclinux.net.
If you wanted to start a whole new process: konqueror "http://imaclinux.net/"
Notes to Using dcop:
- The app your trying to talk to must be running first before you try to talk to it.
- dcop is case sensative -- KonquerorIface is different from konqueroriface (the second willjust give you an error.
- Use quotes were neccessary to escape bash meta characters.
- QString means the argument must be a string.
- int means it must be a number.
- Specify pid with application name (in appname-426 format) when you want to speak to a specfic running process.
- Kwin currently can't be called on by dcop to iconify windows or the alike, afaik. But you can do that using kstart when starting an app.
Examples
Play CD Track 8 in kscd:
dcop kscd CDPlayer settrack 8; dcop kscd CDPlayer play
Note you have to select the track, then click play, the same way it would work if you were directly interacting with kscd.
Refresh Kweather Data:
dcop kweather weatherIface refresh
No way yet to switch kweather to offline mode via. dcop
Go to Desktop 3:
dcop kwin KWinInterface setCurrentDesktop 3
Desktop must be specfied as a int (number).
Logout from KDE:
dcop kdesktop KDesktopIface logout
You can disable the logout prompt by changing the setting in one of the kcms
Set KDE Background to North Beach Wallpaper, Repeated:
dcop kdesktop KBackgroundIface setWallpaper "northbeach.jpg" 3
The last argument must be a number coresponding to the number of the item in the pulldown Mode list in the Background kcm.
1 = Centered, 2 = Tiled, 3 = Center Tile, 4 = Center Maxpect, 5 = Scaled, 6 = Centered Auto Fit
Put Panel On Top of Screen:
dcop kicker Panel setPanelPosition 2
0 = left, 1 = right, 2 = top, 3 = bottom, 4 = werid (discovered via. experimentation)
Conclusion
This howto should give you some insight on how to use dcop to your advantage with KDE 2. Using kdcop you can discover the many parts that can be access from the dcop command. KDE 3 will offer many additonal scripting options with dcop, when I get my hands on it, I'll update this howto.
A can also be found on my homepage. You may freely copy, modify, translate or use this howto to suit your purposes.
-