How do I get the name of the wifi network I'm connected to?

Solution 1:

/Sy*/L*/Priv*/Apple8*/V*/C*/R*/airport -I | awk '/ SSID:/ {print $2}'

This uses the airport CLI, with the -I flag to show information and filter using awk for just the SSID shows the name of the network.

Solution 2:

Great answer here by grg, but just wanted to add this option in case it is useful for someone to extract the SSID and only the SSID:

/Sy*/L*/Priv*/Apple8*/V*/C*/R*/airport -I | grep -w SSID | awk '{print $2}'