diff --git a/disable_bluetooth.sh b/disable_bluetooth.sh index 510da7e..6860f32 100644 --- a/disable_bluetooth.sh +++ b/disable_bluetooth.sh @@ -1,5 +1,6 @@ #!/bin/bash + blueutil --power 0 # Uncomment to debug -# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log +# echo "[$(date)] :attempting to disable bluetooth" >> ~/bluetooth.log \ No newline at end of file diff --git a/enable_bluetooth.sh b/enable_bluetooth.sh index 4565b12..d3aef41 100644 --- a/enable_bluetooth.sh +++ b/enable_bluetooth.sh @@ -1,5 +1,12 @@ #!/bin/bash +SLEEP_SCRIPTS_DIR=~/.sleepscripts + blueutil --power 1 +# Go through PairedDevices.txt and connect +while read device; do + blueutil --connect $device & +done < ${SLEEP_SCRIPTS_DIR}/PairedDevices.txt + # Uncomment to debug # echo "[$(date)] :attempting to enable bluetooth" >> ~/bluetooth.log diff --git a/setup.sh b/setup.sh index 81560ad..113f7e4 100644 --- a/setup.sh +++ b/setup.sh @@ -94,16 +94,22 @@ echo "***********************" echo "Preparing sleep scripts" echo "***********************" +# Create PairedDevices.txt file in KBOS directory - contains the list of paired devices +blueutil --paired | tr -d ',' | awk 'NR>0 { print $2 }' > PairedDevices.txt + + # Determine and escape absolute paths of sleepwatcher and Blueutil SLEEPWATCHER_PATH=$(which sleepwatcher | sed 's_/_\\/_g') BLUEUTIL_PATH=$(which blueutil | sed 's_/_\\/_g') -# Copy sleepscripts to user directory +# Copy sleepscripts, PairedDevices.txt to user directory mkdir -p ${SLEEP_SCRIPTS_DIR} || exit 1; sed "s/blueutil/${BLUEUTIL_PATH}/" ./disable_bluetooth.sh > \ ${SLEEP_SCRIPTS_DIR}/disable_bluetooth.sh || exit 1; sed "s/blueutil/${BLUEUTIL_PATH}/" ./enable_bluetooth.sh > \ ${SLEEP_SCRIPTS_DIR}/enable_bluetooth.sh || exit 1; +sed "s/blueutil/${BLUEUTIL_PATH}/" ./PairedDevices.txt > \ + ${SLEEP_SCRIPTS_DIR}/PairedDevices.txt|| exit 1; chmod +x ${SLEEP_SCRIPTS_DIR}/* || exit 1; echo "** sleep scripts copied to ${SLEEP_SCRIPTS_DIR}"