diff --git a/bt b/bt index 92d6660..611cd04 100755 --- a/bt +++ b/bt @@ -263,9 +263,15 @@ case $choice in all_devices="$(bluetoothctl devices | cut -d' ' -f2)" if ! echo "$dev_id" | grep -q "$all_devices"; then scan on + start_scan="$(cat /tmp/bt_start_scan$$)" echo "Scan on" - notify-send "bt" "Scanning for new devices..." - sleep "$SCAN_PERIOD" + notify-send "bt" "Scanning for new devices until wanted device has been found" + while ! echo "$dev_id" | grep -q "$all_devices"; do + sleep 1 + all_devices="$(bluetoothctl devices | cut -d' ' -f2)" + time_scanned="$(( $(date +'%s') - start_scan ))" + [ "$time_scanned" -gt 30 ] && exit 1 + done fi echo Attempting to pair... bluetoothctl pair "$dev_id"