Background for the question
So im developing a small posix shell script that is meant to revolve around Bluetooth and since im considering "publishing" it to the public im at the phase of both optimizing it and later share the code with others so i can get it reviewed.
The question
The way im getting every bluetooth device that paired with the host, ie the device running this shell script, is:
busctl tree org.bluez > $tempfile
while read mac; do
t=$(echo "${mac##*/dev_}"| grep -v "└─/org")
a=${t%%/*}
#Discard repeats due to there being "sub-adresses"
if [ -z "$a" ] || [ "$a" != "$t" ]; then
continue;
fi
#There's other code running here
done < $tempfile
and then having the object names inside the loop i just use them to return their address, and also other properties which i won't go into detail, like so
c=$(busctl get-property $SERVICE $OBJ_TEMPLATE"$a" $INTERFACE Address)
c=${c##s }
# will return something like " 00:00:00:dd:33:22"
which for the most part is useless as from what I've seen the object name given by busctl tree, when formatted, corresponds to what it will reply from the property address
The thing is im scared that due to some kind of corruption on the busctl part or on the device part those could mismatch, where both could still function but only if i treat the object name as an alias and not as a fixed generic fixed naming convention
exe: when doing busctl tree it will reply on one of the lines: ├─/org/bluez/hci0/dev_00_00_00_00_B5_C8
but get-property will return s 22:33:21:25:AA:B4
You might be better getting the information on what devices are available from calling
GetManagedObjects
on theorg.freedesktop.DBus.ObjectManager
interface.For example:
To get just the devices that are in the cache (and their address) you could easily grep that information:
To find if devices are paired you can add that to the grep: