You can use the GetManagedObjects
method on the org.freedesktop.DBus.ObjectManager
interface. But that won't print just list of paths but dump the entire object so you'd need to parse the paths from the outputted dictionary.
If busctl
(from systemd) is an option for you, I'd recommend using it because it has JSON output so you can parse it with jq
. Example for UDisks2 JSON dump:
# busctl call org.freedesktop.UDisks2 /org/freedesktop/UDisks2 org.freedesktop.DBus.ObjectManager GetManagedObjects --json=short | jq ".data[0] | keys[]"
"/org/freedesktop/UDisks2/Manager"
"/org/freedesktop/UDisks2/block_devices/sda"
"/org/freedesktop/UDisks2/block_devices/sda1"
...
With dbus-send
the call would look like
# dbus-send --system --dest=org.freedesktop.UDisks2 --type=method_call --print-reply /org/freedesktop/UDisks2 org.freedesktop.DBus.ObjectManager.GetManagedObjects
but you need to parse the output manually.
Edit: For org.bluez
the commands are:
# busctl call org.bluez / org.freedesktop.DBus.ObjectManager GetManagedObjects --json pretty | jq ".data[0] | keys[]"
"/org/bluez"
"/org/bluez/hci0"
"/org/bluez/hci0/dev_00_1B_66_C1_56_01"
and
# dbus-send --system --dest=org.bluez --type=method_call --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObject
and you can try something like
# dbus-send --system --dest=org.bluez --type=method_call --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects | grep -A 1 "dict entry" | grep "object path" | cut -d"\"" -f2
/org/bluez
/org/bluez/hci0
/org/bluez/hci0/dev_00_1B_66_C1_56_01
for parsing the output to get just the object paths.
dbus-send --system --dest=org.bluez --type=method_call --print-reply / org.freedesktop.DBus.ObjectManager.GetManagedObjects
but unfortunately doesn't work for bluealsa (the service I need to get object paths from) because the interface is missing
– Luis May 12 '22 at 09:09dbus-send
command working with bluez. Something more advanced for parsing the output thangrep | grep | cut
would be probably better but I was never good withawk
and/orsed
. – Vojtech Trefny May 12 '22 at 12:23