Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.6: Switch between two wireless networks in one location Network
For one reason or another, I have two wireless networks available to me to use in one location. One is DHCP enabled, while the other requires manual setup.

The obvious solution for switching between these networks is to use the Locations feature in Networking to save two profiles, and then use the drop-down Location menu to switch between them. However, I have found that because my MacBook has the logins for both networks saved, it does not switch the wireless network, just the settings. Once you mix DHCP with manual settings, it just fails to work, and requires more intervention.

My solution (admittedly inelegant, but I don't know how to implement a better way), was to create a shell script that will switch the locations, and power cycle the AirPort card (which means it picks up the 'preferred' network). This is then set as a Service using Automator, and assigned a keyboard shortcut. I have also had to configure sudo to allow my user to run it without a password.

Here's the script, which I saved in my home folder and named AirPortReset: In the /etc/sudoers file, I made the following entries:
User_Alias      NET = Richard
Cmnd_Alias      LOC = /Users/Richard/*
NET     ALL=NOPASSWD: LOC
There are two Automator Services to set up (one to cycle between network one and two, and one to reset to the Automatic location). In Automator, create a new Service. Set the top drop downs to No Input and Any Application. From the Utilities Actions, choose Run Shell Script and drag to the workflow area. For the first Service, the entry in the workflow should be:
/usr/bin/sudo /Users/yourname/AirPortReset
And for the second Service, it should be:
/usr/bin/sudo /Users/yourname/AirPortReset auto
Save these as AirportReset & AirportReset Automatic, and now you can use the keyboard shortcut feature to assign them a shortcut key -- I used Command-F5 and Command-F6. Now when I press Command-F5, I cycle between the two wireless networks effortlessly, and when I am somewhere else, I press Command-F6 to revert to the normal Automatic location.
    •    
  • Currently 1.78 / 5
  You rated: 1 / 5 (9 votes cast)
 
[10,100 views]  

10.6: Switch between two wireless networks in one location | 9 comments | Create New Account
Click here to return to the '10.6: Switch between two wireless networks in one location' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Switch between two wireless networks in one location
Authored by: Mauries on Oct 07, '09 08:13:15AM
Maybe I am not getting it clearly but couldn't that be easier fixed by using one of these applications:

- Location X; http://homepage.mac.com/locationmanager/;
- Locations; http://www.codehackers.net/locations/;
- NetworkLocation; http://centrix.ca/NetworkLocation/;

Especially the last one NetworkLocation seems to be very capable. Correct me if I'm wrong though!

[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: Mauries on Oct 07, '09 08:29:52AM
Or what about the free MarcoPolo ( http://www.symonds.id.au/marcopolo/ )

[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: shk on Oct 07, '09 08:34:18AM

I am doing the switch frequently, but i have the following pb, and didn't find anything on google that might help:

when i switch networks , or even ips on the same network, Mail.app loses connectivity with the server (i use imap) , and also the gmail notifier (which uses imap too) loses connectivity, and there is no way to regain it except switching back to the old ip. i suppose there is some kind of imap connection caching feature that's under the hood in os x but i couldn't find anything about that on google. any ideas ?



[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: zacht on Oct 07, '09 08:39:15AM

I am sorry if this is a stupid question, but what is wrong with using the AirPort menu to select which wireless network you want to use? Is the point simply to have a keyboard shortcut to switch between wireless networks?



[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: RaceTripper on Oct 07, '09 08:54:32AM

Or you could just go into the Network preference pane and for each location profile, go under Advanced->Airport and either remove or lower the priority of the access point you don't want from the list of Preferred Networks.



[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: ctierney on Oct 07, '09 09:15:17AM

Maybe you already tried, but I wonder if ifconfig en1 down; ifconfig en1 up might be enough to reset the airport card.



[ Reply to This | # ]
10.6: Switch between two wireless networks in one location
Authored by: BobHarris on Oct 07, '09 04:35:16PM
You may want to just use
/usr/sbin/scselect "new location name"
scselect without any arguments will tell you the available lcoations with your current location prefixed with an *

Then again, I do not have Snow Leopard, so I don't know if the scseclect command still exists.

[ Reply to This | # ]

10.6: Switch between two wireless networks in one location
Authored by: neier on Oct 08, '09 12:36:27AM
In 10.6, /usr/sbin/networksetup has been enhanced above and beyond 10.5

You can now -setairportnetwork directly, and not have to mess with locations.

I just verified with ifconfig that immediately after using networksetup to set the network, the DHCP information was renewed per the new network.

/usr/sbin/networksetup -setairportnetwork AirPort (SSID) (PASSWORD)

So, it shouldn't be too much trouble to make an applescript that toggles between two or more networks in that fashion.

Not sure if the IMAP or Google mail issues would be solved by this or not.

[ Reply to This | # ]

Marco Polo
Authored by: happygiraffe on Oct 12, '09 11:53:47AM
I've always found Marco Polo to be an excellent solution for these sort of things…

[ Reply to This | # ]