Detect If On HotSpot (For Low Data PowerMode)

applebit924
New Contributor

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!

3 REPLIES 3

jhuls
Contributor III

I'm intrigued by this but I'm seeing the following...

Print: Entry, ":KnownNetworks::PersonalHotspot", Does Not Exist

applebit924
New Contributor

What operating system are you running @jhuls ? I am running 10.15.6; I have not tested it on any previous OS.

jhuls
Contributor III

Same...10.15.6.

To be clear it displays the following...

Print: Entry, ":KnownNetworks::PersonalHotspot", Does Not Exist
PCNet wifi.ssid.50434e6574

PCNet is the ssid I'm connected to at the moment. I'm not familiar with the data after that and obviously the message before that seems out of place.