Posted By

griffman on 01/10/13


Tagged

Bash terminal airport


Versions (?)

Toggle AirPort off/on


 / Published in: Bash
 

This bash script toggles the status of the AirPort card in a Mac. Note that the code that determines the interface ID is really a hack, and likely to break at any time. Replace with a hardcoded interface ID for best reliability.

  1. #/bin/bash
  2.  
  3. # To toggle airport
  4.  
  5. # Get the AirPort interface name
  6. # Note this is very fragile; hard code if you wish
  7.  
  8. SYSVER=`sw_vers | grep ProductVersion | cut -c 17-20`
  9.  
  10. if [ $SYSVER = "10.6" ]
  11. then
  12. INTFC=`networksetup -listnetworkserviceorder | grep "AirPort.*:" | cut -c 34-36`
  13. else
  14. INTFC=`networksetup -listnetworkserviceorder | grep "Wi-Fi.*:" | cut -c 32-34`
  15. fi
  16.  
  17. STATUS=`ifconfig | grep "$INTFC.*RUNNING"`
  18. LENGTH=${#STATUS}
  19.  
  20. if [ $LENGTH = 0 ]
  21. then
  22. # AirPort is presently off
  23. networksetup -setairportpower "$INTFC" on
  24. else
  25. # AirPort is presently on
  26. networksetup -setairportpower "$INTFC" off
  27. fi

Report this snippet  

You need to login to post a comment.