```
#!/bin/bash
# A small script to turn Bluetooth off if no devices are connected.
# Can be run with a crontab periodically. E.g. to check every 10 minutes...
# */10 * * * *
num_connected=$(bluetoothctl info | grep 'Connected: yes' | wc -l)
if [ $num_connected -eq 0 ]; then
echo "No devices connected, turning Bluetooth off"
bluetoothctl power off
else
echo "$num_connected devices connected, leaving Bluetooth on"
fi
```