Toggle adapter status with applescript on Lion

Note: this script requires Satimage’s applescript additions(regex in particular) available here(they are downloadable together with smile).

//this script needs the scripting additions of Smile http://www.satimage.fr/software/en/smile/index.html
set servList to do shell script ("networksetup -listnetworkserviceorder")

set match to ""

try
set match to find text "^\\([0-9*]+\\)[^
]+" in servList with regexp and all occurrences
end try

set devList to {}
set lan to 1
repeat with dev in match
set devName to matchResult of dev
set devList to devList & {devName}
end repeat

set devBox to choose from list devList without multiple selections allowed
if devBox is false then
return
end if
set devAnswer to item 1 of devBox

set servName to ""
try
set servName to matchResult of (find text "^\\([0-9*]+\\)([^
]+)" in devAnswer using "\\1" with regexp)
end try

if (offset of "*" in devAnswer) > 0 then
do shell script ("networksetup -setnetworkserviceenabled " & servName & " on")
display alert devAnswer & " has been enabled!" as informational buttons {"Ok"} giving up after 5
else
do shell script ("networksetup -setnetworkserviceenabled " & servName & " off")
display alert devAnswer & " has been disabled!" as informational buttons {"Ok"} giving up after 5
end if