set/get property using dbus-send

Prashant Gaur picture Prashant Gaur · Feb 6, 2018 · Viewed 11.8k times · Source

I have made below sample xml and need some help in forming dbus-send command to set/get propoerty "Status". I know how to call methods, but not able to read/write property using dbus-send.

xml:

<node>
    <interface name="com.pgaur.GDBUS">
        <method name="HelloWorld">
            <arg name="greeting" direction="in" type="s"/>
            <arg name="response" direction="out" type="s"/>
        </method>
        <signal name="Notification">
            <arg name="roll_number" type="i"/>
            <arg name="name" type="s"/>
        </signal>
        <property name="Status" type="u" access="readwrite"/>
    </interface>
</node>

Answer

Ravi picture Ravi · Feb 7, 2018

You can Get/Set DBus properties for your DBus interface using below dbus-send commands. Replace $BUS_NAME and $OBJECT_PATH with respective names.

Get Property:

dbus-send --system --dest=$BUS_NAME --print-reply $OBJECT_PATH \
org.freedesktop.DBus.Properties.Get string:com.pgaur.GDBUS string:Status

Set Property:

dbus-send --system --dest=$BUS_NAME --print-reply $OBJECT_PATH \
 org.freedesktop.DBus.Properties.Set string:com.pgaur.GDBUS string:Status variant:uint32:10

You can read DBus specification to know more about DBus Properties.