Map pid to qdbus service numbers after startup

I am trying to write a bash script that will run a program (console) and send dbus messages to it. Here is my experiment

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

Displays

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 specific konsole instance that I just created?


Here's a bad hacking 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 of course the best way!

+5
source share
1 answer

Try starting a new instance of Konsole using the D-Bus API with qdbus org.kde.konsole /Konsole newSession. It will return a session identifier that can later be used to manage it using calls to the /Session/$SIDservice object org.kde.konsole.

0
source

All Articles