1 <refentry id="gdbus" lang="en">
5 <productname>GIO</productname>
8 <contrib>Developer</contrib>
9 <firstname>David</firstname>
10 <surname>Zeuthen</surname>
11 <email>zeuthen@gmail.com</email>
17 <refentrytitle>gdbus</refentrytitle>
18 <manvolnum>1</manvolnum>
19 <refmiscinfo class="manual">User Commands</refmiscinfo>
23 <refname>gdbus</refname>
24 <refpurpose>Tool for working with D-Bus objects</refpurpose>
29 <command>gdbus</command>
30 <arg choice="plain">introspect</arg>
32 <arg choice="plain">--system</arg>
33 <arg choice="plain">--session</arg>
34 <arg choice="plain">--address <replaceable>address</replaceable></arg>
36 <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
37 <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
39 <arg choice="plain">--xml</arg>
42 <arg choice="plain">--recurse</arg>
45 <arg choice="plain">--only-properties</arg>
49 <command>gdbus</command>
50 <arg choice="plain">monitor</arg>
52 <arg choice="plain">--system</arg>
53 <arg choice="plain">--session</arg>
54 <arg choice="plain">--address <replaceable>address</replaceable></arg>
56 <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
58 <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
62 <command>gdbus</command>
63 <arg choice="plain">call</arg>
65 <arg choice="plain">--system</arg>
66 <arg choice="plain">--session</arg>
67 <arg choice="plain">--address <replaceable>address</replaceable></arg>
69 <arg choice="plain">--dest <replaceable>bus_name</replaceable></arg>
70 <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
71 <arg choice="plain">--method <replaceable>org.project.InterfaceName.MethodName</replaceable></arg>
73 <arg choice="plain">--timeout <replaceable>seconds</replaceable></arg>
75 <arg choice="plain">ARG1</arg>
76 <arg choice="plain" rep="repeat">ARG2</arg>
79 <command>gdbus</command>
80 <arg choice="plain">emit</arg>
82 <arg choice="plain">--system</arg>
83 <arg choice="plain">--session</arg>
84 <arg choice="plain">--address <replaceable>address</replaceable></arg>
86 <arg choice="plain">--object-path <replaceable>/path/to/object</replaceable></arg>
87 <arg choice="plain">--signal <replaceable>org.project.InterfaceName.SignalName</replaceable></arg>
89 <arg choice="plain">--dest <replaceable>unique_bus_name</replaceable></arg>
91 <arg choice="plain">ARG1</arg>
92 <arg choice="plain" rep="repeat">ARG2</arg>
95 <command>gdbus</command>
96 <arg choice="plain">wait</arg>
98 <arg choice="plain">--system</arg>
99 <arg choice="plain">--session</arg>
100 <arg choice="plain">--address <replaceable>address</replaceable></arg>
102 <arg choice="plain">--activate <replaceable>bus_name</replaceable></arg>
104 <arg choice="plain">--timeout <replaceable>seconds</replaceable></arg>
106 <arg choice="plain"><replaceable>bus_name</replaceable></arg>
109 <command>gdbus</command>
110 <arg choice="plain">help</arg>
115 <title>Description</title>
117 <command>gdbus</command> is a simple tool for working with D-Bus objects.
121 <title>Commands</title>
124 <term><option>introspect</option></term>
126 Prints out interfaces and property values for a remote object.
127 For this to work, the owner of the object needs to implement the
128 <literal>org.freedesktop.DBus.Introspectable</literal> interface.
129 If the <option>--xml</option> option is used, the returned
130 introspection XML is printed, otherwise a parsed pretty
131 representation is printed.
132 The <option>--recurse</option> option can be used to
133 introspect children (and their children and so on) and the
134 <option>--only-properties</option> option can be used to
135 only print the interfaces with properties.
139 <term><option>monitor</option></term>
141 Monitors one or all objects owned by the owner of
142 <replaceable>bus_name</replaceable>.
146 <term><option>call</option></term>
148 Invokes a method on a remote object. Each argument to pass to the
149 method must be specified as a serialized
150 <link linkend="GVariant"><type>GVariant</type></link> except that strings do
151 not need explicit quotes. The return values are printed out as
152 serialized <link linkend="GVariant"><type>GVariant</type></link>
157 <term><option>emit</option></term>
159 Emits a signal. Each argument to include in the signal must be specified as a serialized
160 <link linkend="GVariant"><type>GVariant</type></link> except that strings do
161 not need explicit quotes.
165 <term><option>wait</option></term>
167 Waits until <replaceable>bus_name</replaceable> is owned by some
168 process on the bus. If the <option>--activate</option> is specified,
169 that bus name will be auto-started first. It may be the same as the
170 bus name being waited for, or different.
174 <term><option>help</option></term>
176 Prints help and exit.
183 <title>Bash Completion</title>
185 <command>gdbus</command> ships with a bash completion script to
186 complete commands, destinations, bus names, object paths and
187 interface/method names.
192 <title>Examples</title>
193 This shows how to introspect an object - note that the value of each
194 property is displayed:
196 $ gdbus introspect --system \
197 --dest org.freedesktop.NetworkManager \
198 --object-path /org/freedesktop/NetworkManager/Devices/0
199 node /org/freedesktop/NetworkManager/Devices/0 {
200 interface org.freedesktop.DBus.Introspectable {
202 Introspect(out s data);
204 interface org.freedesktop.DBus.Properties {
212 GetAll(in s interface,
215 interface org.freedesktop.NetworkManager.Device.Wired {
217 PropertiesChanged(a{sv} arg_0);
219 readonly b Carrier = false;
220 readonly u Speed = 0;
221 readonly s HwAddress = '00:1D:72:88:BE:97';
223 interface org.freedesktop.NetworkManager.Device {
227 StateChanged(u arg_0,
231 readonly u DeviceType = 1;
232 readonly b Managed = true;
233 readwrite o Ip6Config = '/';
234 readwrite o Dhcp4Config = '/';
235 readwrite o Ip4Config = '/';
236 readonly u State = 2;
237 readwrite u Ip4Address = 0;
238 readonly u Capabilities = 3;
239 readonly s Driver = 'e1000e';
240 readwrite s Interface = 'eth0';
241 readonly s Udi = '/sys/devices/pci0000:00/0000:00:19.0/net/eth0';
246 The <option>--recurse</option> and <option>--only-properties</option> options can be useful when wanting to inspect all objects owned by a particular process:
249 $ gdbus introspect --system --dest org.freedesktop.UPower --object-path / --recurse --only-properties
252 node /org/freedesktop {
253 node /org/freedesktop/UPower {
254 interface org.freedesktop.UPower {
256 readonly b IsDocked = true;
257 readonly b LidForceSleep = false;
258 readonly b LidIsPresent = false;
259 readonly b LidIsClosed = false;
260 readonly b OnLowBattery = false;
261 readonly b OnBattery = false;
262 readonly b CanHibernate = true;
263 readonly b CanSuspend = true;
264 readonly s DaemonVersion = '0.9.10';
266 node /org/freedesktop/UPower/Policy {
268 node /org/freedesktop/UPower/Wakeups {
269 interface org.freedesktop.UPower.Wakeups {
271 readonly b HasCapability = true;
280 In a similar fashion, the <option>introspect</option> command can be
281 used to learn details about the <literal>Notify</literal> method:
285 interface org.freedesktop.Notifications {
287 GetServerInformation(out s return_name,
289 out s return_version,
290 out s return_spec_version);
291 GetCapabilities(out as return_caps);
292 CloseNotification(in u id);
293 Notify(in s app_name,
306 With this information, it's easy to use the <option>call</option>
307 command to display a notification
310 $ gdbus call --session \
311 --dest org.freedesktop.Notifications \
312 --object-path /org/freedesktop/Notifications \
313 --method org.freedesktop.Notifications.Notify \
318 "Here's the body of the notification" \
325 Monitoring all objects on a service:
328 $ gdbus monitor --system --dest org.freedesktop.ConsoleKit
329 Monitoring signals from all objects owned by org.freedesktop.ConsoleKit
330 The name org.freedesktop.ConsoleKit is owned by :1.15
331 /org/freedesktop/ConsoleKit/Session2: org.freedesktop.ConsoleKit.Session.ActiveChanged (false,)
332 /org/freedesktop/ConsoleKit/Seat1: org.freedesktop.ConsoleKit.Seat.ActiveSessionChanged ('',)
333 /org/freedesktop/ConsoleKit/Session2: org.freedesktop.ConsoleKit.Session.ActiveChanged (true,)
334 /org/freedesktop/ConsoleKit/Seat1: org.freedesktop.ConsoleKit.Seat.ActiveSessionChanged ('/org/freedesktop/ConsoleKit/Session2',)
337 Monitoring a single object on a service:
340 $ gdbus monitor --system --dest org.freedesktop.NetworkManager --object-path /org/freedesktop/NetworkManager/AccessPoint/4141
341 Monitoring signals on object /org/freedesktop/NetworkManager/AccessPoint/4141 owned by org.freedesktop.NetworkManager
342 The name org.freedesktop.NetworkManager is owned by :1.5
343 /org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x5c>},)
344 /org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x64>},)
345 /org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x5e>},)
346 /org/freedesktop/NetworkManager/AccessPoint/4141: org.freedesktop.NetworkManager.AccessPoint.PropertiesChanged ({'Strength': <byte 0x64>},)
353 $ gdbus emit --session --object-path /foo --signal org.bar.Foo "['foo', 'bar', 'baz']"
357 Emitting a signal to a specific process:
360 $ gdbus emit --session --object-path /bar --signal org.bar.Bar someString --dest :1.42
364 Waiting for a well-known name to be owned on the bus; this will
365 <emphasis>not</emphasis> auto-start the service:
368 $ gdbus wait --session org.bar.SomeName
372 Auto-starting then waiting for a well-known name to be owned on the bus:
375 $ gdbus wait --session --activate org.bar.SomeName
379 Auto-starting a different service, then waiting for a well-known name to be
380 owned on the bus. This is useful in situations where
381 <replaceable>SomeName</replaceable> is not directly activatable:
384 $ gdbus wait --session --activate org.bar.PrerequisiteName org.bar.SomeName
388 Waiting for a well-known name and giving up after 30 seconds. By default,
389 the timeout is disabled; or set <option>--timeout</option> to 0 to disable it:
392 $ gdbus wait --session --timeout 30 org.bar.SomeName
400 Please send bug reports to either the distribution bug tracker
401 or the upstream bug tracker at
402 <ulink url="https://gitlab.gnome.org/GNOME/glib/issues/new"/>.
407 <title>See Also</title>
410 <refentrytitle>dbus-send</refentrytitle><manvolnum>1</manvolnum>