Thank you for the sample code, it was helpful to get started! Trying this out, I would lean towards using a library for anything non-trivial. First impressions from my armchair are that D-Bus has a non-standard data and type wire format that I would not like to learn, the protocol can be used to publish a service, and processes can notify one another. The spec is a bit big, for example defining its own authentication on top of SASL, and it seems that none of the BEAM libraries implement the whole spec yet.
For now though, I have similarly limited needs as others here and I can hide the ad-hoc bits in a single-purpose module. I’m trying to detect and integrate with a local music player, so I wanted the session pointed to by the logged-in user’s DBUS_SESSION_BUS_ADDRESS environment variable, which is passed through to the System.cmd transparently. This makes the send method simpler,
def send(dest, object_name, action, message \\ nil) do
{output, 0} =
System.cmd(
"dbus-send",
[
"--session",
"--print-reply=literal",
"--dest=#{dest}",
object_name,
action
] ++ if(message, do: [message], else: [])
)
output
end
My usage can ignore the custom data serialization for now,
def mediaplayer2_available?() do
send(
"org.freedesktop.DBus",
"/org/freedesktop/DBus",
"org.freedesktop.DBus.ListNames"
)
|> String.match?(~r/MediaPlayer2/)
end






















