Script Wi-Fi SSID switch if on SSID "X"

Solution 1:

Here is a way to do it:

[[ $(networksetup -getairportnetwork en0 | awk -F': ' '{print $2}') == "CompanyA" ]] && networksetup -setairportnetwork en0 "CompanyB"

Solution 2:

Test ([) if the output of networksetup is the same as the string CompanyA if so then change the SSID to CompanyB.

curssid=$(networksetup -getairportnetwork en0 | cut -d ' ' -f4-)

if [ "$curssid" = CompanyA ]
then
networksetup -setairportnetwork en0 "CompanyB"
fi