Subject: Re: Wifi / Airport

From: [email-masked]
Date: Thu, 28 Feb 2013 05:10:39 -0800 (PST)

You can give this script a try. It works for me. As Rob says, it probably 
works faster if you export it as an application and trigger it rather than 
running it as a script. I call mine Toggle Wifi and use 'tw' to activate 
it. Works like a charm!
-------------------------
set res to do shell script airportUtil & " -p || exit 0"
property airportUtil : 
"/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport 
-I"

if res contains "off" then
-- Toggle Airport on
do shell script "networksetup -setairportpower en1 on 2>/dev/null"
set apStatus to true
else if res contains "on" then
-- Toggle Airport off
do shell script "networksetup -setairportpower en1 off 2>/dev/null"
set apStatus to false
end if
-----------------------------------
Rich

---

From: Rob Griffiths <[email-masked]>
Date: Wed, 9 Jan 2013 08:59:26 -0800

On Jan 9, 2013, at 8:01 AM, Michael Ullyot wrote:

> Is it possible to use Butler to turn the Airport / wifi on or off with a keystroke?

Yes, though it took me a bit of work to figure out :). Create the following shell script somewhere, save it (I called mine airtoggle) and make it executable (chmod 755 airtoggle):

#/bin/bash

# Get the AirPort interface name
# Note this is very fragile; hard code if you wish
INTFC=`networksetup -listnetworkserviceorder | grep "AirPort.*:" | cut -c 34-36`

STATUS=`ifconfig | grep "$INTFC.*RUNNING"`
LENGTH=${#STATUS}

if [ $LENGTH = 0 ]
then
  # AirPort is presently off
  networksetup -setairportpower "$INTFC" on
else
  # AirPort is presently on
  networksetup -setairportpower "$INTFC" off
fi

In Butler, create a new AppleScript item, with these contents:

do shell script "/full/path/to/the/script/airtoggle"

Change the path bit to refer to the actual path to your script, then assign a hot key, and you're done. Notes:

* The bit to figure out the AirPort interface is liable to break; feel free to replace it with hardcoded references to your AirPort network.

* In theory, you could do this all within Butler with the "do shell script" bits, but I prefer to call saved scripts for more complex stuff.

* Someone smarter than I could probably find a better way to determine if AirPort was running; I grepped the output of ifconfig for the phrase "RUNNING," which only appears when AirPort is on.

This worked for me, but your mileage may vary :)

-rob.

---

From: Michael Ullyot <[email-masked]>
Date: Wed, 9 Jan 2013 08:01:23 -0800 (PST)

Is it possible to use Butler to turn the Airport / wifi on or off with a 
keystroke?

Here's a blog post whose link to an Applescript isn't working at the 
moment: 
http://tumblr.caseyliss.com/post/9332404411