Skip to content

Instantly share code, notes, and snippets.

@luckman212
Created January 23, 2022 21:14
Show Gist options
  • Save luckman212/efec7df3fdea3163341ebbb7144c8415 to your computer and use it in GitHub Desktop.
Save luckman212/efec7df3fdea3163341ebbb7144c8415 to your computer and use it in GitHub Desktop.
When Airdrop stops working, this might fix it without requiring a reboot...
#!/usr/bin/env bash
# requires blueutil: `brew install blueutil`
if ! sudo -v ; then
echo requires root
exit
fi
function dots() {
for (( c=$1; c>0; c-- )); do
echo -n '.'
sleep 1
done
echo "done"
}
# make sure BrowseAllInterfaces is false
echo -n "setting com.apple.NetworkBrowser prefs..."
defaults write com.apple.NetworkBrowser BrowseAllInterfaces -bool false
defaults remove com.apple.NetworkBrowser DisableAirDrop 2>/dev/null
echo "done"
# bounce Bluetooth daemon
echo -n "kickstarting com.apple.bluetoothd"
sudo launchctl kickstart -kp system/com.apple.bluetoothd >/dev/null
dots 3
# turn Bluetooth and WiFi off
echo -n "turning off Bluetooth and WiFi"
blueutil -p 0
networksetup -setairportpower en1 off
dots 3
# turn Bluetooth and WiFi on
echo -n "turning on Bluetooth and WiFi"
blueutil -p 1
networksetup -setairportpower en1 on
dots 3
echo
echo "try AirDrop again!"
@luckman212
Copy link
Author

luckman212 commented Aug 7, 2022

This is a shell script. Save it as plaintext (I recommend Sublime Text for this, or VSCode). Click the "raw" button on the top right of this page to get the plain text version.

A good place to put it is /usr/local/bin/airdropfix.sh but anywhere in your $PATH is fine.

Open a Terminal and type

chmod +x /usr/local/bin/airdropfix.sh

Now you should be able to type airdropfix.sh in any Terminal and the script will run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment