A faster version for Sequoia (which also determines the correct WiFi interface enX):
ipconfig getsummary "$(networksetup -listallhardwareports | awk '/Wi-Fi|AirPort/{getline; print $NF}')" | grep ' SSID : ' | awk -F ': ' '{print $2}'
Takes 46 ms vs. 3.8 s on my system.