3 ms·
A hacky python wrapper around bluetoothctl that lets me use aliases as addresses. So I can write `connect {niss}` to connect my phone instead of `connect 12:6a:
by iudqnolq 7y ago
A hacky python wrapper around bluetoothctl that lets me use aliases as addresses. So I can write `connect {niss}` to connect my phone instead of `connect 12:6a:78:c2:74:d5 (ref. to one of childhood favorite books, Startide Rising).
The script then runs "devices", looks for an alias "niss", and substitutes in the corresponding address. I use expect in Python to script it all together.
- iudqnolq 7y agoGot back to my laptop, here it is (extremely hacky): https://gist.github.com/danielzfranklin/bb4848ffda1d44b437e2a9d7c8a8f3f5 https://gist.github.com/danielzfranklin/bb4848ffda1d44b437e2... All commands you enter pass directly to bluetoothctl except aliases in curly braces are replaced. You can use it interactively or pipe to it. Complex piped stuff may or may not actually work. If stdin isn't a tty the program exits once bluetoothctl reports a success/failure after it gets an EOF on stdin. This means you can write `btctl <<< "connect {my_device_alias}"` and it will exit once it's done connecting or couldn't connect. If you're using it interactively it only waits 0.01 seconds for results before displaying them and moving on to the next input() (whereas bluetoothctl will asynchronously display more results even while you're typing in a new input) so you may need to spam enter to see results.