Skip to content

Instantly share code, notes, and snippets.

@sinanm89
Forked from ralph089/.wakeup
Created July 5, 2016 07:39
Show Gist options
  • Save sinanm89/0902394395161b8d75f95f5bcf1ed468 to your computer and use it in GitHub Desktop.
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.
#!/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