Last active
August 29, 2015 14:07
-
-
Save farfanoide/4ceddb421cad9471db76 to your computer and use it in GitHub Desktop.
Script to toggle wifi card on a mac
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
| #!/usr/bin/env bash | |
| # ------------------------------------------------------------------------------ | |
| # Description | |
| # ----------- | |
| # | |
| # Simple script to toggle wifi on and off on a mac. | |
| # It doesn't take many interfaces into account. | |
| # | |
| # ------------------------------------------------------------------------------ | |
| # Author | |
| # ------- | |
| # | |
| # * Farfanoide (https://github.com/farfanoide) | |
| # | |
| # ------------------------------------------------------------------------------ | |
| _cut_and_clean() { cut -d: -f 2 | tr -d ' ' ;} | |
| _get_device() { grep -i wi-fi -2 | grep -i device | _cut_and_clean ;} | |
| wifi_interface=$(networksetup -listallhardwareports | _get_device) | |
| wifi_status=$(networksetup -getairportpower $wifi_interface | _cut_and_clean) | |
| [ "$wifi_status" = "Off" ] && status="On" || status="Off" | |
| networksetup -setairportpower $wifi_interface $status && echo "Wi-Fi: ${status}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment