Skip to content

Instantly share code, notes, and snippets.

@farfanoide
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save farfanoide/4ceddb421cad9471db76 to your computer and use it in GitHub Desktop.

Select an option

Save farfanoide/4ceddb421cad9471db76 to your computer and use it in GitHub Desktop.
Script to toggle wifi card on a mac
#!/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