Skip to content

Instantly share code, notes, and snippets.

@douglasresende
Last active August 29, 2015 13:57
Show Gist options
  • Save douglasresende/9901932 to your computer and use it in GitHub Desktop.
Save douglasresende/9901932 to your computer and use it in GitHub Desktop.
Auto Connect Wifi Mac OS
#!/bin/bash
# http://magp.ie/2012/07/09/mac-osx-shell-script-to-automate-connecting-to-wifi-network/
AIRPORT="en1"; #may be en0, use networksetup -listallhardwareports to check
WIFI_NETWORK_NAME="nomedarede"
WIFI_PASSWORD="senhadarede"
SCRIPT_PATH="$(pwd)/wifi.sh"
if networksetup -getairportnetwork $AIRPORT | grep -i -a $WIFI_NETWORK_NAME ;
then
PROMPT_COMMAND='echo -ne "\033]0;"WIFI: OK"\007"'
else
PROMPT_COMMAND='echo -ne "\033]0;"WIFI: OFF"\007"'
osascript -e 'tell app "System Events" to display notification "WiFi OFF"'
networksetup -setairportnetwork $AIRPORT $WIFI_NETWORK_NAME $WIFI_PASSWORD
fi
sleep 10
clear
sh $SCRIPT_PATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment