Here is an updated script that works for macOS 26 devices, seems Apple will change the ability to get the SSID via terminal and will most likely remove it at some point.
#!/bin/bash
# Enable verbose mode for ipconfig sudo ipconfig setverbose 1
# Get the current SSID and display it for interface en0 SSID=$(ipconfig getsummary en0 | awk -F ' SSID : ' '/ SSID : / {print $2}')
# Check if SSID is found if [ -n "$SSID" ]; then echo "Connected SSID: $SSID" else echo "SSID not found or not connected." fi
Very annoying behaviour from Apple to block all these APIs. Especially as this info is clearly available in the system preferences.
Luckily they forgot about the WiFi scan cache, so I’m fudging around this like so:
#!/bin/bash
# macOS Tahoe WiFi SSID extraction # Apple redacts SSID from all public APIs, but the CachedScanRecord # in scutil still contains the actual network data in a binary plist!
get_ssid_from_scutil() { local hex_data xml_data
# Query scutil for the AirPort state (contains CachedScanRecord) hex_data=$(scutil <<EOF 2>/dev/null | grep "CachedScanRecord" | sed 's/.*<data> 0x//' open show State:/Network/Interface/en0/AirPort quit EOF )
@DPop I just saw this, i have been using that slow version as work around but going to setverbose 1 temporarily to pull it for certain scripts until Apple probbably removes it as well.
I use the following Script which also lists an active LAN Device. Thanks to @dan-snelson to find the SSID name.
#!/bin/sh
#################################################################################################### # # A Jamf Pro EA which determines the Mac's currently selected network interface. # #################################################################################################### # # Based on a EA Script from Dan K. Snelson (@dan-snelson) # ####################################################################################################
# Get the list of active devices from scutil active_devices=$(/usr/sbin/scutil --nwi | awk -F': ' '/Network interfaces:/{print $NF}')
# Loop over the list of active devices for device in $(printf '%s\n' "$active_devices"); do if [[ ! "$device" =~ "utun" ]]; then # Get the name of the port associated with the device id, such as "Wi-Fi" port_name=$(/usr/sbin/networksetup -listallhardwareports | grep -B1 "$device" | awk -F': ' '/Hardware Port:/{print $NF}') # Add that name into an array port_names+=("$port_name") fi done
# Prepare the Result ActiveNetworkInterface="Missing" ActiveNetworkInterface=$(printf '%s\n' "${port_names[@]}") if [[ "$ActiveNetworkInterface" = "" ]]; then result="Missing" elif [[ "$ActiveNetworkInterface" =~ "Wi-Fi" ]]; then currentSSID result="$ActiveNetworkInterface - $SSIDname" else result="$ActiveNetworkInterface" fi
# Print back the array as the returned value echo "<result>$result</result>"