I'm trying to automate the pairing of my headset to my ubuntu16 machine.
I took this nice script and tried it, but it didn't work. I played around a bit, and found out that I can just work with this minimal script:
#!/usr/bin/expect -f
set prompt '#'
set address [lindex $argv 0]
spawn bluetoothctl &> /dev/null
expect -re $prompt
send "\nconnect <my_mac_addr>\r"
sleep 10
I save this as a ./bluetooth.sh and run it with ./bluetooth.sh & and it works like a charm. However, I get this annoying bluetoothctl
output:
[NEW] Controller *** ### [default]
[NEW] Device *** A
[NEW] Device *** B
[NEW] Device *** C
[bluetooth]#
I tried removing it with the redirection I added to the spawn command, but it didn't help as you can see...
Removing the expect
would work, but I'm not sure this is the way to go...
You don't really need to use
expect
and can give commands tobluetoothctl
directly as arguments.For a more complete example, here is the full Bash script that I use in Ubuntu 20.04 for my BT radio :
This assumes the destination
$mac
is already paired of course.Capture the output and strip the prompts...