1

I'm stuck on a script to switch a Mac to a different SSID if its already connected to a certain SSID.

What I need the script to do is:

Check what SSID the Mac Wi-Fi is using

If it is on SSID called "CompanyA" switch to SSID called "CompanyB" If it is not on SSID called "CompanyA" do nothing.

I can get SSID currently connected to with

networksetup -getairportnetwork en0 | cut -d ":" -f2

and I can switch with

networksetup -setairportnetwork en0 "CompanyB"

But I don't know how to do the if on CompanyA then switch to CompanyB

1

Here is a way to do it:

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

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

You must log in to answer this question.

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