I know how to find it out in Objective C, but I need to do this in a shell script.

(I could compile and install one of the example programs given in the link, but surely there is already a command line program installed that will give me this information?)

I have MacOS X Yosemite, 10.10.2.

2 Answers 2

/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.

  • 2
    If the SSID includes spaces, you will need something like /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I | awk -F: '($1 ~ "^ *SSID$"){print $2}' | cut -c 2- instead. Commented Oct 27, 2021 at 2:59
  • sed-based approach to return SSIDs with spaces: /Sy*/L*/Priv*/Apple8*/V*/C*/R*/airport -I | sed -n "s/^.*SSID: \(.*\)$/\1/p"
    – goodov
    Commented Apr 18, 2022 at 10:18
  • it just returns: AirPort: Off
    – alper
    Commented May 15, 2023 at 6:10

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}'

  • 3
    I can confirm that the grep/awk pipeline works. But at least for me, on Mojave 10.14.2, airport is not in my /usr/local/sbin nor anywhere else on my $PATH.
    – dave4420
    Commented Jan 25, 2019 at 8:04
  • It looks like this was either removed as of Mojave (it is not present in Catalina or Big Sur either), or was something specific to my system. I removed this from my answer...
    – Scot
    Commented Dec 28, 2020 at 20:46
  • grep SSID | grep -v BSSID | awk … looks strange, isn‘t there an easier way?
    – nohillside
    Commented Dec 28, 2020 at 22:38
  • @nohillside Yes, grep -w will work, and is cleaner. Changed...
    – Scot
    Commented Dec 28, 2020 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .