If you didn't want to have so many spaces in your call, you can use
/usr/bin/wdutil info | /usr/bin/awk '/SSID/ { print $NF }' | head -n 1
This one works for me.
#!/bin/sh
##Get the wireless port ID
WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')
##What SSID is the machine connected to
SSID=$(networksetup -getairportnetwork "$WirelessPort" | cut -d " " -f4)
echo "<result>$SSID</result>"
This one works for me.
#!/bin/sh
##Get the wireless port ID
WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')
##What SSID is the machine connected to
SSID=$(networksetup -getairportnetwork "$WirelessPort" | cut -d " " -f4)
echo "<result>$SSID</result>"
@daniel_behan As of macOS 14.5 Apple changed
/usr/bin/wdutil info
to return "redacted" for MAC Address, SSID, and BSSID so calling networksetup as your EA does is currently the only way to get the SSID.
I don't know if whoever at Apple though removing that info from wdutil will do the same to networksetup but here's hoping.
This one works for me.
#!/bin/sh
##Get the wireless port ID
WirelessPort=$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')
##What SSID is the machine connected to
SSID=$(networksetup -getairportnetwork "$WirelessPort" | cut -d " " -f4)
echo "<result>$SSID</result>"
Is there any way to get the BSSID as well?