Connecting to wireless via script

I am trying to create an apple script that will allow the user to double click on a apple script app and have it connect to our wireless network. I am having an issue as we have a WPA2 enterprise network that needs both a user name and password. I can get it to connect to the network but then it asks for the user name and password. I am not sure how to pass along these within the script. Here is the command i am using.

sudo networksetup -setairportnetwork AirPort WIRELESS-WPA username:password


the man page says

-setairportnetwork network hardwareport [password] Set AirPort Network to <network> using optional [password] if specified.
so it expects only a password and network and hardwareport must swap

sudo networksetup -setairportnetwork WIRELESS-WPA Airport password

You could also get the password out of the keychain, if there is a key for it

property SSID : "WIRELESS-WPA"

tell application "Keychain Scripting" to set myKey to password of first key of current keychain whose name is SSID
do shell script "networksetup setairportnetwork " & SSID & " Airport " & myKey

I don’t know, if networksetup requires root privileges in Snow Leopard.
If so you must add with administrator privileges

This will allow me to add the password, but i need to add the user name also. We are using AD, so i need to let it know both the password and the user name.

I remember a while back that you would somehow pass both the username and password along and i thought it was if you did username:password but i could be wrong.

What is AD?

normally the access to wireless base stations requires only a password

Active Directory.

Then I guess you can’t do it with networksetup, which considers only the standard password-only authentication