Desktop COmmunication Protocol, DCOP, is a lightweight mechanism for inter-process communication.
DCOP allows the user to interact with programs that are currently running.
KDE supplies two programs to utilitize DCOP:
dcop, a command-line program, and
kdcop, a GUI program.
A few notes about using
dcop
:
-
dcop
[options] [application [object [function [arg1] [arg2] ... ] ] ]
-
Applications that can open more than one window at a time will be listed as
<application>-PID
-
All the arguments are case-sensitve. setFullScreen and setfullscreen are two different functions.
-
The regular expression token * can be used in the application and object arguments.
%
dcop
kon*
konqueror-16006
konsole-8954
Some example commands and their output are below:
When there is more than one application/object, which one should you use?
Got a reference?
%
echo
$KONSOLE_DCOP
DCOPRef(konsole-7547,konsole)
%
dcop
$KONSOLE_DCOP
newSession
session-6
%
dcopstart
konsole
konsole-9058
#!/bin/sh
konsole=$(dcopstart konsole-script)
session=$(dcop $konsole konsole currentSession)
dcop $konsole $session renameSession Local
session=$(dcop $konsole konsole newSession)
dcop $konsole $session renameSession Remote
session=$(dcop $konsole konsole newSession)
dcop $konsole $session renameSession Code
dcop $konsole $session sendSession 'cd /my/work/directory'
KDE DIY - Building Your Own Tools
You can use KDE dialogs from your own scripts, to combine the power
of UNIX� shell scripting with the ease of use of KDE.
kdialog
--msgbox 'You have new mail!'
kdialog
--title 'New Mail'
--msgbox 'You have new mail!'
The KDialog part can be replaced via
--caption
option
kdialog
--title 'New Mail'
--msgbox 'You have new mail!'
--dontagain myfile:mykey
Saves whether to show again in
$
KDEHOME
/share/config/myfile
(by writing
into this file the following lines:
[Notification Messages]
mykey=false
Instead of
--msgbox
you can also use
--sorry
and
--error
, as appropriate. For
instance, you might use
kdialog
--sorry 'The
network can not be reached'
or
kdialog
--error 'Mail box can not be opened'
.
It is also possible to create message boxes that accept a yes or no
answer.
kdialog
--yesno 'Do you want to connect
to the Internet?'
echo
$?
Make sure to store the result in a variable if you do not use it
directly, the next command will fill $? with a new value You can use
--dontagain
here as well, it will remember the users choice
and returns it the next times without showing the dialog any more.
Further variations are:
-
--warningyesno
-
like
--yesno
but with a different
icon
-
--warningcontinuecancel
-
With
Continue
and
Cancel
buttons.
-
--warningyesnocancel
-
With
Yes
,
No
and
Cancel
button. For example:
kdialog
--warningyesnocancel 'Do you want
to save the changes?'
kdialog
--inputbox "Enter your name:" "YourName"
The result is printed to stdout, to put it in a variable you can use
name=$(kdialog --inputbox "Enter your name:"
"YourName")
. The last argument is optional, it is used to
pre-fill the dialog.
password
=$(
kdialog
--password "Enter your password:"
)
The
--dontagain
option does not work with
--inputbox
or
--password
There are two dialogs that let the user make a choice from a
list:
-
--menu
-
Lets the user select a single item from a list.
-
--checklist
-
Lets the user select one or more items from a list.
city
=$(
kdialog
--menu "Select a city" a London b Madrid c Paris d Berlin
)
$city
will a, b, c or d.
city
=$(
kdialog
--checklist "Select cities" a London off b Madrid on c Paris on d Berlin off
)
Madrid and Paris will be pre-selected. The result with Madrid and
Paris selected will be "b"
"c".
If you add the
--separate-output
option, it will put
b and c each on a line
of its own, making the result easier to process.
file=$(kdialog --getopenfilename $HOME)
file=$(kdialog --getopenfilename $HOME "*.png *.jpg|Image Files")
file=$(kdialog --getsavefilename $HOME/SaveMe.png)
file=$(kdialog --getexistingdirectory $HOME)