Created
February 21, 2024 05:23
-
-
Save webleon/8de3632a3d21fe1a670a9563703c45f2 to your computer and use it in GitHub Desktop.
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
# Some of the hackintosh machines with Boardcom Wi-Fi/BT cards may suffer from high CPU usage after wakeup. | |
# This issue is due to a daemon called "bluetoothd" that uses a lot of CPU resources. | |
# These scripts attempt to resolve this issue with Sleepwatcher. | |
# Install | |
# /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
# brew install sleepwatcher | |
# brew install blueutil | |
# cp .sleep .wakeup ~/ | |
# chmod +x ~/.sleep ~/.wakeup | |
# Config and test the scripts | |
# /usr/local/sbin/sleepwatcher --verbose -s ~/.sleep -w ~/.wakeup | |
# Run sleepwatcher as a service | |
# brew services start sleepwatcher |
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 | |
# Output file to store connected device IDs | |
OUTPUT_FILE="$HOME/connected_devices.log" | |
# Clear previous history | |
> "$OUTPUT_FILE" | |
# Record connected device IDs | |
/usr/local/bin/blueutil --connected | awk '{print $2}' | sort | uniq | tr -d ',' >> "$OUTPUT_FILE" |
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 | |
# Output file to store connected device IDs | |
OUTPUT_FILE="$HOME/connected_devices.log" | |
# Function to kill bluetoothd process and reconnect devices | |
kill_bluetoothd_and_reconnect() { | |
# Check if bluetoothd process exists | |
if pgrep -x "bluetoothd" > /dev/null; then | |
# Kill bluetoothd process without typing password | |
echo "password" | sudo -S kill -HUP $(pgrep bluetoothd) &> /dev/null | |
# Wait before reconnecting | |
sleep 1 | |
# Read the log file and reconnect each device | |
while IFS= read -r device_id; do | |
/usr/local/bin/blueutil --connect "$device_id" &> /dev/null | |
done < "$OUTPUT_FILE" | |
else | |
echo "bluetoothd process does not exist. Exiting." | |
fi | |
} | |
# Execute function to kill bluetoothd process and reconnect devices | |
kill_bluetoothd_and_reconnect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment