Skip to content

Instantly share code, notes, and snippets.

@fsmv
Last active December 11, 2015 14:58
Show Gist options
  • Save fsmv/4617401 to your computer and use it in GitHub Desktop.
Save fsmv/4617401 to your computer and use it in GitHub Desktop.
A wifi utility for Mac that gets status and sets state. To use you have to place the airport binary in your path per these instructions http://osxdaily.com/2007/01/18/airport-the-little-known-command-line-wireless-utility/
#!/bin/bash
# Run this command to link airport into the path
# sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/sbin/airport
if [ "$1" == "status" ]
then
out=$(airport -I)
if [ "$out" == "AirPort: Off" ]
then
echo "Status: off"
else
echo "Status: on"
fi
else
if [ "$1" == "on" ]
then
networksetup -setairportpower en1 on
elif [ "$1" == "off" ]
then
networksetup -setairportpower en1 off
else
#If it gets here, none of the arguments were correct
echo "Usage: wifi [status|on|off]"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment