Created
February 12, 2013 15:58
-
-
Save knice/4770886 to your computer and use it in GitHub Desktop.
Look for and connect to WiFi network.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| ## This script checks to see if the Mac is connected to | |
| ## a particular network. If it isn't, the script shuts off | |
| ## the wifi radio and turns it back on, then attempts | |
| ## to connect to the specified network. | |
| ## | |
| ## You can run this script at regular intervals with | |
| ## an app called Lingon, which utilizes launchd. | |
| ## Just make sure to chmod -x the script first. | |
| network="YOUR_NETWORK_NAME" | |
| password="YOUR_NETWORK_PASSWORD" | |
| confirmStr="Current Wi-Fi Network: "$network | |
| networkTest=`networksetup -getairportnetwork en1` | |
| if [ "$networkTest" = "$confirmStr" ] | |
| then | |
| echo "You are on the expected network" | |
| else | |
| networksetup -setairportpower en1 off | |
| networksetup -setairportpower en1 on | |
| networksetup -setairportnetwork en1 $network $password | |
| echo `networksetup -getairportnetwork en1` | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I created this because I'm having issues with a laptop driving a public display on a flaky WiFi network. I don't have control over the flaky WiFi and I don't have easy access to the building to deal with issues that can't be solived via remote access (like, say, flaky WiFi).
I plan to set the laptop to automatically sleep at regular intervals and when it wakes up, I'd like for it to check it's internet connection.