How to programmatically get available wifi networks without airport utility? Is there a way other than using the airport command line utility to get the list of available wifi networks programmatically (for consumption by an application)?  Here is the context:

I have a command line application for managing wifi networks (https://github.com/keithrbennett/wifiwand, gem install wifi-wand) in which I get the list of available wifi networks using airport -s.

Unfortunately, because the network names are presented right aligned, there is no way to determine whether or not, or how many, leading spaces the name contains. There is a -x option to output the data in XML format, but in Ruby, parsing XML usually requires installing the nokogiri gem, which is legendarily problematic, and I don't want to impose that on my users. So I go through this weird and less than 100% reliable process to return the correct results in most but not all cases.

What are my other options, if any, for getting this information?
You could (mis)use awk to filter the result:

airport -s -x| awk '          { if (catch == 1) { print; catch=0 } }
                   /SSID_STR/ { catch=1 }'
&lt;string&gt;UPC Wi-Free&lt;/string&gt;
&lt;string&gt;UPCE191589&lt;/string&gt;
&lt;string&gt;The Cloud&lt;/string&gt;
&lt;string&gt;UPCE191589&lt;/string&gt;
&lt;string&gt;The Cloud&lt;/string&gt;


Not very nice, but does the job :-)

OTOH, a SSID can be anything, it doesn't even need to be printable (see Is there a standard that defines what is a valid SSID and password?). So any attempt to handle SSID in text-based utilities will likely fail sooner or later.