dbus-send
Send messages to D-Bus
SYNOPSIS
dbus-send [OPTIONS] OBJECT_PATH INTERFACE.MEMBER [ARGUMENTS...]
Common Usage Examples:
dbus-send --session --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.ListNames
dbus-send --system --type=signal --dest=com.example.Service /com/example/Object com.example.Interface.Event string:"Hello"
PARAMETERS
--session
Instructs dbus-send to connect to the D-Bus session bus. This is the default if no bus type is specified.
--system
Instructs dbus-send to connect to the D-Bus system bus. This bus is typically used for system-wide services.
--address=ADDRESS
Specifies a custom D-Bus address to connect to, overriding --session or --system. Useful for connecting to non-standard or private D-Bus instances.
--print-reply
For method calls, this option makes dbus-send block and wait for a reply message from the service, then print its contents to standard output. If omitted, method calls are fire-and-forget.
--dest=NAME
The well-known bus name of the D-Bus service that should receive the message (e.g., org.freedesktop.DBus). This is a mandatory component for method calls and signals.
--type=MESSAGE_TYPE
Defines the type of D-Bus message to send. Defaults to method_call. Other common types include signal, method_return, and error.
OBJECT_PATH
The D-Bus object path on the destination service to which the message is directed (e.g., /org/freedesktop/DBus).
INTERFACE.MEMBER
The D-Bus interface and member (method or signal) name to be invoked or emitted (e.g., org.freedesktop.DBus.ListNames). The format is InterfaceName.MemberName.
TYPE:VALUE
Arguments to the method call or signal. Each argument must be specified as a type:value pair, where type is a D-Bus type code (e.g., string, int32, boolean, double) and value is the corresponding data. Multiple arguments are space-separated.
Examples: string:"hello", int32:123, boolean:true.
DESCRIPTION
dbus-send is a command-line utility used to send messages to a D-Bus message bus. D-Bus is a robust system for inter-process communication (IPC), enabling applications to communicate by exposing objects and methods, or by emitting and listening for signals. dbus-send provides a direct interface for interacting with D-Bus services from the shell, making it invaluable for scripting, debugging, and testing D-Bus functionality. Users can specify the target bus (session or system), the destination service name, the object path, the interface, the method to call or signal to emit, and arguments with their specific D-Bus types. Its simplicity makes it a quick tool for one-off interactions or integration into shell scripts.
CAVEATS
- Complex Type Handling: Specifying complex D-Bus type signatures (e.g., arrays, structs, dictionaries) can be cumbersome and error-prone on the command line due to verbose syntax.
- Limited Introspection: While useful for basic interaction, dbus-send does not provide built-in introspection capabilities to discover available methods or signals. Tools like busctl or gdbus are better suited for this.
- Permission Requirements: Correct D-Bus security policies must be in place for dbus-send to successfully communicate with services. Permission denied errors are common if policies are not configured correctly.
- Synchronous vs. Asynchronous: Method calls are asynchronous by default; use --print-reply to make them synchronous. Signals are always asynchronous.
COMMON USE CASES
dbus-send is frequently used for:
- Debugging and Testing: Directly invoking methods on a D-Bus service during development or troubleshooting.
- System Administration: Scripting interactions with system services exposed via D-Bus, such as NetworkManager, UDisks, systemd, or PolicyKit.
- Custom Signaling: Emitting custom signals for other applications to receive, useful in event-driven scripting.
- Connectivity Checks: Verifying D-Bus service availability and basic functionality.
D-BUS TYPE SYSTEM
Successful use of dbus-send relies on understanding the D-Bus type system. Arguments must be prefixed with their D-Bus type (e.g., string:"hello", int32:123, boolean:true, double:3.14). For aggregates like arrays, structs, and dictionaries, specific syntax is required (e.g., array:string:"item1","item2", struct:int32:1,string:"name"). Incorrect type specification is a common source of errors and will lead to D-Bus errors.
HISTORY
D-Bus was conceived as part of the freedesktop.org project, with its initial release around 2002-2003, aiming to standardize inter-process communication for Linux desktop environments (GNOME, KDE) and later for system services. dbus-send was included as one of the fundamental command-line utilities within the dbus package. It was designed to provide a straightforward, scriptable interface for interacting with D-Bus services, proving invaluable for system administrators, developers, and power users for debugging, testing, and automating D-Bus interactions from the command line from the early days of D-Bus adoption.
SEE ALSO
dbus-monitor(1), gdbus(1), busctl(1), qdbus(1)