Skip to content

Instantly share code, notes, and snippets.

@webleon
Created February 21, 2024 05:23
Show Gist options
  • Save webleon/8de3632a3d21fe1a670a9563703c45f2 to your computer and use it in GitHub Desktop.
Save webleon/8de3632a3d21fe1a670a9563703c45f2 to your computer and use it in GitHub Desktop.
# 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
#!/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"
#!/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