I'm using Mac 10.9.5. When I'm at a Starbucks, my computer will automatically connect to their WiFi network. However, after an hour, they kick you off and although you are still connected to their network, beneath your "WiFi" icon in your Network System preferences, you now have a "Self Assigned IP" and are unable to connect to the Internet. The only way to reconnect is to click the "Turn Wi-Fi Off" button and then click "Turn Wi-Fi On" button to re-enable things.
My question is, how do I write a script to automatically do this for me? What I woudl like is some script run in the background if I'm connected to a network named "Google Starbucks" and then if the script notcied I have a "Self Assigned IP", it woudl turn wi-fi off and turn it back on again without my having to do anything.
Best Answer
In AppleScript use:
do shell script "networksetup -setairportpower en0 off; sleep 2; networksetup -setairportpower en0 on"
although you might have to changeen0
to the appropriate adapter which you can get from the Network Utility.If you want it in a BASH script don't use the
do shell script
part and the rest can be on one line or remove the;
adding a newline in there place. You could swap thedisplay dialog ...
in Buscar웃's script with this if you want.