I'm trying to write an extension that listens for a DBus signal, but I don't know the path ahead of time. Actually, there are multiple paths (unique for each application that implements the interface). There seems to be no way to determine the path ahead of time (ie. at application startup), so I'm left with listening for the signal that gets emitted when I send a certain DBus command. What I'm really looking for is the GJS equivalent of the Python solution to this question. Unfortunately, the various DBus proxies don't allow null
or undefined
as values for the path like the Python library does. I've also tried using imports.dbus.session.watch_signal
which receives all the signals that are emitted but gives me no way to tie the sender back to a specific signal.
1 Answer
I am unfamiliar with GJS (definitely worth looking into) however, if there is a GJS command line interface then dbus-monitor
can track the d-bus by any message attribute.
Quoting man dbus-monitor
:
EXAMPLE
Here is an example of using dbus-monitor to watch for the gnome typing
monitor to say things
dbus-monitor "type='signal', \
sender='org.gnome.TypingMonitor', \
interface='org.gnome.TypingMonitor'"
and
In order to get dbus-monitor to see the messages you are interested in,
you should specify a set of watch expressions as you would expect to be
passed to the dbus_bus_add_match function.
and quoting D-Bus: Message bus APIs: dbus_bus_add_match function:
Possible keys you can match on are type, sender, interface, member,
path, destination and numbered keys to match message args
(keys are 'arg0', 'arg1', etc.). Omitting a key from the rule indicates
a wildcard match. For instance omitting the member from a match rule but
adding a sender would let all messages from that sender through regardless
of the member.
Note that the sender is identified in the output of the following
The problem of too much output from
dbus-monitor "type='signal'"
such as
...
signal sender=:1.47 -> dest=(null destination) serial=1679 path=/org/ayatana/bamf/application311805604; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
string "org.ayatana.bamf.view"
array [
dict entry(
string "Active"
variant boolean true
)
]
array [
]
...
signal sender=:1.51 -> dest=com.canonical.Unity.Panel.Service serial=1674 path=/com/canonical/Unity/Panel/Service; interface=com.canonical.Unity.Panel.Service; member=ReSync
string "libappmenu.so"
...
signal sender=:1.51 -> dest=com.canonical.Unity.Panel.Service serial=1681 path=/com/canonical/Unity/Panel/Service; interface=com.canonical.Unity.Panel.Service; member=ReSync
string "libdatetime.so"
...
can be pruned by, or with combinations of:
dbus-monitor --profile "type='signal'"
dbus-monitor "type='signal'" | grep '...some pattern...'
dbus-monitor "type='signal', interface='...'"
or another key instead of interface
etc.
The last variant might be most applicable to find a signal
on the d-bus "that implements the interface"
.
Bookmark:
Gnome Shell JS - Listen for DBus signal on an interface for any path