Controlling KDE activities via dbus
KDE can be controlled from the command line with qdbus
. The general syntax is qdbus COMPONENT PATH METHOD ARGUMENT1...
where COMPONENT
is typically something like org.freedesktop.Foo
or org.kde.Bar
, PATH
denotes a class exposed by the component, METHOD is the name of a particular action in that class, and there may be further arguments depending on the method.
Here are commands for KDE ≥4.7 to list activities, to get the current activity, and to set the current activity.
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.ListActivities
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.CurrentActivity
qdbus org.kde.kactivitymanagerd /ActivityManager org.kde.ActivityManager.SetCurrentActivity "activity identifier "
Finding out what dbus can do
KDE's dbus documentation is very poor. Each class is minimally documented, e.g. Activity, DesktopCorona). But you'll probably have to experiment and perhaps read the source (there are links in the API documentation pages) to find out what is available.
If you type qdbus
with up to two arguments, it will list the possibilities for the next argument. The following shell snippet lists all available Qt-dbus methods:
for x in $(qdbus | sed '/^:/d'); do
for y in $(qdbus $x); do
qdbus $x $y | sed "s~^~$x $y ~"
done
done 2>/dev/null >qdbus.list
Another way to explore the dbus tree is qdbusviewer
in the Qt development tools. There is also a Python qt-dbus interface as part of PyQt.
Getting the shell to react
To make a shell react to external events, the best you can reasonably do is make it check something before displaying a prompt. Bash runs $PROMPT_COMMAND
before displaying a prompt, and zsh executes the precmd
function. So you can look up the current KDE activity and do something if it's changed from the last time you looked.
Type C-u
before either M-:
or M-!
to get the result inserted instead of sent to the echo area.
To get things directly into the kill ring, you need to dabble in Elisp. Something like this (untested):
;;; kill ring version of M-!
(defun shell-command-to-kill-ring (command)
(interactive
(list
(read-shell-command "Shell command: " nil nil
(let ((filename
(cond
(buffer-file-name)
((eq major-mode 'dired-mode)
(dired-get-filename nil t)))))
(and filename (file-relative-name filename))))
current-prefix-arg
shell-command-default-error-buffer))
(kill-new (shell-command-to-string command)))
;;; kill-ring version of M-:
(defun eval-expression-to-kill-ring ()
(interactive)
(call-interactively 'eval-expression)
(kill-new (car values)))
Best Answer
Emacs can be built with the GTK toolkit and GTK style can be configured to emulate the KDE/Qt look. It won't be a real Qt app, but it will look like one.