Skip to content

Instantly share code, notes, and snippets.

@nlgthuan
Created October 1, 2023 01:05
Show Gist options
  • Select an option

  • Save nlgthuan/267d5340cd137491326fd69ddfc05e69 to your computer and use it in GitHub Desktop.

Select an option

Save nlgthuan/267d5340cd137491326fd69ddfc05e69 to your computer and use it in GitHub Desktop.
Script to toggle bluetooth off and on in MacOS using bluutil
#!/bin/bash
# Turn off Bluetooth
echo "πŸ”„ Turning off Bluetooth..."
blueutil --power 0
if [ $? -eq 0 ]; then
echo "βœ… Bluetooth has been turned off."
else
echo "❌ Failed to turn off Bluetooth."
exit 1
fi
# Sleep for 1 second
echo "⏱ Waiting for 1 second..."
sleep 1
# Turn Bluetooth back on
echo "πŸ”„ Turning on Bluetooth..."
blueutil --power 1
if [ $? -eq 0 ]; then
echo "βœ… Bluetooth has been turned back on."
else
echo "❌ Failed to turn on Bluetooth."
exit 1
fi
echo "πŸŽ‰ Script executed successfully."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment