How can I write an AppleScript which when run will connect to a specific WIFI network if available? The title pretty much sums it up. I want to avoid having to use the trackpad to connect to certain networks. This comes up often when a new network becomes available but I'm already connected to another one.
You can also use ControlPlane:


Enable "Nearby WiFi Network" from the Evidence Sources tab.
Add a nearby WiFi network rule from the Rules tab.
Add a Network Location or Run Shell Script action from the Actions tab.