-
-
Save sinanm89/0902394395161b8d75f95f5bcf1ed468 to your computer and use it in GitHub Desktop.
Restarts Bluetooth Module on Mac OS X El Capitan. Use it with SleepWatcher to automatically restart your Bluetooth Module on wakeup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Restart Bluetooth Module on Mac OS X | |
# | |
# Requires Blueutil to be installed: http://brewformulas.org/blueutil | |
BT="/usr/local/bin/blueutil" | |
log() { | |
echo "$@" | |
logger -p notice -t bt_restarter "$@" | |
} | |
err() { | |
echo "$@" >&2 | |
logger -p error -t bt_restarter "$@" | |
} | |
if [ -f "$BT" ]; then | |
if [[ $("$BT" power) == *1 ]]; | |
then | |
echo "Bluetooth on, restarting ..." | |
($("$BT" power 0) &> /dev/null && echo "Bluetooth Module stopped") || (err "Couldn't stop Bluetooth Module" && exit 1) | |
($("$BT" power 1) &> /dev/null && echo "Bluetooth Module started") || (err "Couldn't start Bluetooth Module" && exit 1) | |
log "Successfully restarted Bluetooth" && exit 0 | |
else | |
echo "Bluetooth is off, nothing to do ..." | |
fi | |
else | |
err "Couldn't find blueutil, please install http://brewformulas.org/blueutil" && exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment