Call DBus methods in the Gjs / Gnome shell

If I have a bus name, an object path, and an interface, how do I call DBus methods from Gjs (in the gnome-shell extension)?

I am looking for the equivalent of the following python code:

import dbus
bus = dbus.SessionBus()
obj = bus.get_object("org.gnome.Caribou.Keyboard", "/org/gnome/SessionManager/EndSessionDialog")
obj.Open(0, 0, 120, dbus.Array(signature="o"))

(Note that I didn’t explicitly use the interface due to some python-dbus magic, but I could have iface = dbus.interface(obj, "org.gnome.SessionManager.EndSessionDialog"). Since I have the interface name, I am fine with the solution that requests it. Note that this example would be stupid in Gjs as it refers to gnome-shell)

+5
source share
2 answers

Import imports.dbusdeprecated with gnome-shell 3.4. A new way is to use Gioas described here :

const Gio = imports.gi.Gio;

const MyIface = '<interface name="org.example.MyInterface">\
<method name="Activate" />\
</interface>';
const MyProxy = Gio.DBusProxy.makeProxyWrapper(MyIface);

let instance = new MyProxy(Gio.DBus.session, 'org.example.BusName',
'/org/example/Path');

( , makeProxyClass, - makeProxyWrapper.)

, , . pidgin/purple :

$ dbus-send --print-reply --dest=im.pidgin.purple.PurpleService \
/im/pidgin/purple/PurpleObject org.freedesktop.DBus.Introspectable.Introspect

.

+8

:

gjs> const DBus = imports.dbus;
gjs> for (let i in DBus) log(i);
+1

All Articles