Macro to switch between 2 different WiFi networks

I am trying to build a macro to connect to 2 different wifi networks at 2 different times. In other words, I want my mac to connect to network A at 9am and to connect to network B at 7pm.
My first approach was to switch on and off the wifi at the predetermined times. However, to be able to connect to the right wifi network, I will have to be able to change the order of my preferred networks using KM. Is this possible?

How else can I go about it?

Can you set up two Network Locations and then change network location (which there is a location for).

I use both networks in then same location. The only variable that changes is time.

Hey Mirizzi,

The point is that you can create different Network Locations (Configurations) in the System Network Preference Pane.

Keyboard Maestro is able to access these and switch between them using the ‘Set Network Location’ Action.


I was not able to set up Network location to work consistently.
So, I used this shell script

networksetup -setairportnetwork en1 “Network Name” password

Can somebody help me with this? I tried this today (5 years after this topic was created) but only get an error message from KeyboardMaestro saying: "Task failed with status 10".

My exact wording is:

networksetup -setairportnetwork en1 “[name of my network]” [password (no quotes here)]

Hey everyone, thanks for all the help in this thread. I recently had to set up a macro in Keyboard Maestro using networksetup and this thread helped.

The only thing I had to do different is change the en1 or the Wi-Fi network interface to en0 because that's what it is on my machine.

I've detailed my findings on how to change networks using networksetup in this post if someone is still wondering how to get it to work.