Awhile back I did a little article on Bluetooth. I also did an article on disabling menu items such as Bluetooth, using Managed Preferences. But I hadn’t looked at granular controls of Bluetooth settings. Luckily, a user submission on the topic just came in and Ted Kidd from Michigan (thanks, Ted!). Ted has provided a script for disabling Bluetooth’s Discoverable mode. His submission:
I’ve found that more than a fair share of preferences are stored for each specific user on a computer. I’ve also found that some preferences are stored in a “ByHost” folder in /Users//Library/Preferences. Anything stored in the ByHost folder has the hardware UUID in the plist file name.
/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c20-57
This line will pull the hardware UUID number so that it can be used in a defaults read/write script or something like that. You probably already know this, but it seems like a good tip to include on a website. I needed to do this to turn off “Discoverable” mode for bluetooth.
defaults write /Users/<user>/Library/Preferences/ByHost/com.apple.Bluetooth.`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57` DiscoverableState -bool no
launchctl unload /System/Library/LaunchDaemons/com.apple.blued.plist
launchctl load /System/Library/LaunchDaemons/com.apple.blued.plistIf using in a login script (via managed prefs), it would look like this:
uuid=`/usr/sbin/system_profiler SPHardwareDataType | grep "Hardware UUID" | cut -c22-57`
/usr/bin/defaults write /Users/$@/Library/Preferences/ByHost/com.apple.Bluetooth.$uuid DiscoverableState -bool no
/usr/sbin/chown $@ /Users/$@/Library/Preferences/ByHost/com.apple.Bluetooth.$uuid.plist
This script will turn discoverablestate to “off” and relaunch the bluetooth service.