5

I am trying to write a bash script which will launch a program (konsole) and send dbus messages to it. Here is my experiment

konsole &
echo pid is $!
ps aux | grep konsole
qdbus | grep konsole

This outputs

pid is 2726
me    2726  0.0  0.4  45404  9952 pts/0    S+   14:59   0:00 konsole
 org.kde.konsole-2729

The qdbus service name is always org.kde.konsole-{pid+epsilon} but the epsilon part is unpredictable.

In my bash script, how do I get the exact qdbus service name for the particular konsole instance I just spawned?


Here's a nasty, hacky solution

qdbus | grep konsole | sed 's/[^0-9]//g' > /tmp/before
konsole &
sleep 1
qdbus | grep konsole | sed 's/[^0-9]//g' > /tmp/after

N=`sort /tmp/before /tmp/after | uniq -u`

but surely there's a better way!

spraff
  • 32,570
  • 22
  • 121
  • 229

2 Answers2

0

you can check PPID of qdbus, to see associated konsole.

Saboteur
  • 1,331
  • 5
  • 12
0

Try launching new Konsole instance via D-Bus API with qdbus org.kde.konsole /Konsole newSession. It will return session ID that can be later used to control it with calls to /Session/$SID object of the org.kde.konsole service.

rkhayrov
  • 10,040
  • 2
  • 35
  • 40
  • 4
    `Service 'org.kde.konsole' does not exist.` but if I launch konsole manually then service `org.kde.konsole.12345` (or similar) exists. `qdbus | grep konsole` lists no results unless I am running at least one konsole. – spraff Apr 01 '12 at 10:42