0

I'm trying to interact with the Notification service through DBus in getting it to send a notification by manually sending in messages to its destination. I will make a call to the Notify method of the interface org.freedesktop.Notifications which has the following signature:

.Notify                             method    susssasa{sv}i u            -

I'm stuck on the part where I have to provide array of type string and variant. But according to the manpage of dbus-send

           <contents>   ::= <item> | <container> [ <item> | <container>...]
           <item>       ::= <type>:<value>
           <container>  ::= <array> | <dict> | <variant>
           <array>      ::= array:<type>:<value>[,<value>...]
           <dict>       ::= dict:<type>:<type>:<key>,<value>[,<key>,<value>...]
           <variant>    ::= variant:<type>:<value>
           <type>       ::= string | int16 | uint16 | int32 | uint32 | int64 | uint64 | double | byte | boolean | objpath

<array> accepts a <type> and not a <container> to which <variant> belongs. So I get an error.

$ dbus-send --session --print-reply --dest=org.freedesktop.Notifications /org/freedesktop/Notifications org.freedesktop.Notifications.Notify \
string:'me' \
uint32:0 \
string:"hello world" \
string:"" \
string:"" \
dict:string:variant:'urgency',byte:1 

dbus-send: Unknown type "variant"

What is the syntax for signature of a{sv}?

1 Answer 1

0

The syntax is indeed dict:string:variant:'urgency',byte:1, but it is only implemented in 'dbus' 1.15.0 or later, which is currently the "development branch" of 'dbus' and not yet found in any distribution.

I would instead recommend either busctl (systemd) or gdbus (GLib2):

busctl call --user org.freedesktop.Notifications \
                   /org/freedesktop/Notifications \
                   org.freedesktop.Notifications Notify \
                   susssasa{sv}i \
                   "me" \
                   0 \
                   "hello world" \
                   "" \
                   "" \
                   0 \
                   1 "urgency" y 1 \
                   0

In busctl the signature is specified upfront (like it would be in the actual D-Bus message on the wire) with all parameters following, e.g. ssu "hello" "world" 123; only variant parameters are immediately preceded by their actual type. Since there are no separators, an array or a dict is specified with its length first, followed by its values or key/value pairs.

gdbus call -e -d org.freedesktop.Notifications \
              -o /org/freedesktop/Notifications \
              -m org.freedesktop.Notifications.Notify \
              "me" \
              0 \
              "hello world" \
              "" \
              "" \
              "[]" \
              "{'urgency': <byte 1>}" \
              0

gdbus generally expects GNOME's GVariant text format syntax, although as a shortcut it will auto-detect the method signature and will accept bare strings – but only if they're a stand-alone parameter, while in other cases strings need to be quoted inside the argument, e.g. "'hello'" for a string parameter (or even as "@s 'hello'" if you want to be really explicit) or "<'hello'>" for a variant(string). Within a dict it would look like "{'key': <'value'>}".

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.