I had it with not knowing if my clients are or not on a hotspot (For Low Data PowerMode) so I wrote something quickly. Now I'll flag certain updates to only download and backup to occur under these conditions.
#!/bin/sh
NETFILE="/Library/Preferences/SystemConfiguration/com.apple.airport.preferences.plist"
CurrentWiFiNetwork=$(networksetup -getairportnetwork en0 | sed "s|^Current Wi-Fi Network: ||")
GetCurrentNetworkSSIDValue()
{
defaults read "$NETFILE" PreferredOrder | grep "wifi.ssid." | sed 's|.* "wifi.ssid.|wifi.ssid.|;s|",$||;s|"$||' | while read wifi_ssid; do
WiFiName=$(/usr/libexec/PlistBuddy -c "print :KnownNetworks:$wifi_ssid:SSID" "$NETFILE")
if [[ "$CurrentWiFiNetwork" == "$WiFiName" ]]; then
echo "$WiFiName $wifi_ssid"
break
fi
done
}
IsHotSpot()
{
GetCurrentNetworkSSIDValue | while IFS=$' ' read WiFiName wifi_ssid; do # in the event there is more than one entry which would be weird
PersonalHotSpot=$(/usr/libexec/PlistBuddy -c "print :KnownNetworks:$wifi_ssid:PersonalHotspot" "$NETFILE")
echo "$WiFiName $PersonalHotSpot"
done
}
IsHotSpot
I broke this up into a couple subroutines so you can pick and choose what you want to do. Enjoy!
