Control KDE applications from a terminal with dcop and kdcop

Ever want to shutdown a KDE application so that it goes through the normal shutdown procedure? Ever want to talk to an application from a script? Enter dcop and kdcop. dcop is a interface that lets you talk to KDE applications from the command line. kdcop is a nice gui interface to query kde's dcop server and see what commands are available for any running appications.

Here is an eaxmple image of me locating the proper dcop call to close kontact.



In this image you can se I searched for the term quit, without searching there are a ton of commands available for kontact. If you click on the execute icon kdcop will call the command and write the output plus the command to the bottom of the window. Now I can enter this into a terminal whith a minor translation.

And presto-chango, Kontact closes.
If you are using NX to login to your Linux Box from another machine and accidentally left kontact open in another session you can close kontact for all sessions like this.

sudo dcop --all-users kontact MainApplication-Interface quit
I know closing an application is  not that exciting, but  I wanted to keep this simple. With dcop you can download mail, create a new email, create calandar events, all kinds of stuff just in Kontact. A lot of programs use dcop, so it is good to get familiar with it. For instance lirc uses dcop allowing you to control applications with your remote control. You can even write quick gui applications using dcop with Kommander, an IDE for creating dcop GUI apps.