Friday, January 06, 2012

Controling airport from command line

I wrote two small scripts to control the power status of the mac airport.
  1. Power cycle the airport
  2. 
    #/bin/bash
    # This script does a power cycle of the airport
    # Pedro Parracho <pedro.parracho@gmail.com>
    
    /usr/sbin/networksetup -setairportpower airport OFF
    /usr/sbin/networksetup -setairportpower airport ON
    
    
     
  3. Toggle the power status
  4. 
    #/bin/bash
    # This script toogles the power status of the airport 
    # Pedro Parracho <pedro.parracho@gmail.com>
    
    airportPower=$(/usr/sbin/networksetup -getairportpower airport| cut -d' ' -f4 | tr '[:lower:]' '[:upper:]')
    
    if [ $airportPower = "ON" ]
    then
        echo airport is ON, turning it OFF
        /usr/sbin/networksetup -setairportpower airport OFF
    else
        echo airport is OFF, turning it ON
        /usr/sbin/networksetup -setairportpower airport ON
    fi