Applescript automated method for setting up WEP and WPA/WPA2 wireless

After much tinkering, testing and hair-pulling, my partners-in-crime and I finally got an automated method for setting up wireless configurations on 10.5 (didn’t bother trying with 10.4 or lower).

We are currently running this from within a PackageMaker3 installer, but it could be run as a stand alone app. This requires the certificate for the WPA network (in PEM format) to be in a known location to be installed into the login.keychain. We’d also added the BigHonkingText command to give the user several reminders to not touch anything or risk messing it up (there are several pauses when dialogs appear that I could never figure out). The code could most probably be cleaned up, but I’m just happy it works at all.

Also, this should be run as the local user with administrator rights, not as root. Messes up the keychain stuff, bad. Really bad. Trust me.

If I could add only one thing, it would be the ability to lock the keyboard/mouse/trackpad to ward off evil spirits.

If you make any use of this (we plan on using it to setup several hundred student laptops or rather let the students set it up themselves), please comment on this topic. I’d like to know that the hours I’ve lost recently went to good use.

set CertName to "name_of_your_certificate"
set WPANameString to "yourWPAnetwork"
set WEPNameString to "yourWEPnetwork"
set WEPPassString to "yourWEPpassword"
set ClearClipboardString to "any bit of text to clear the clipboard"
set theUser to (do shell script "echo $USER")

-- this creates an entry in the system keychain, sets up the wireless connections and sets up permissions on the certificate


try
    tell current application
        activate
        set acctBox to display dialog "Wireless Connection Setup:
Please enter your wireless USERNAME
(Ex. USERNAME@yourdomain.edu)" default answer "" buttons {"Cancel", "OK"} default button 2
        set myAcct to the text returned of acctBox
        set myButton to the button returned of acctBox
        if myButton is "OK" then
            if myAcct is not "" then
                set myPass to display dialog "Please enter your wireless password:" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
                if myPass is not "" then
                    set myMacPassDialog to display dialog "Please enter your Mac/Apple password. (This is the password you used to start the installer)" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
                    set myMacPass to the text returned of myMacPassDialog
                else
                    RestartRoutine()
                end if
            else
                RestartRoutine()
            end if
        else
            RestartRoutine()
        end if
        
        if myAcct contains "@" then
            set myAcct to text 1 through ((offset of "@" in myAcct) - 1) of myAcct
        end if
        
        
        set acctBox to display dialog "Click OK to install then please DO NOT TOUCH the keyboard or mouse/trackpad until wireless setup is complete!" buttons {"Cancel", "OK"} default button 2
        set myButton to the button returned of acctBox
        if myButton is "Cancel" then
            quit
        end if
    end tell
    
    -- MUST Turn off wireless 
    do shell script "networksetup -setairportpower off" user name theUser password myMacPass with administrator privileges
    
    -- MUST Turn on Assistive Devices for script to run properly
    do shell script "sudo touch /private/var/db/.AccessibilityAPIEnabled" user name theUser password myMacPass with administrator privileges
    
    tell application "System Preferences"
        activate
        set the current pane to pane id "com.apple.preference.network"
        get the name of every anchor of pane id "com.apple.preference.network"
        reveal anchor "Advanced Airport" of pane id "com.apple.preference.network"
        tell application "System Events"
            tell application process "System Preferences"
                -- Setup WPA2 network 
                do shell script "/tmp/yourfolder/BigHonkingText -M -p 2 -b orange \"     Please DO NOT TOUCH, be patient.     \""
                click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
                set the clipboard to WPANameString
                click text field 1 of group 1 of window 1
                keystroke "v" using {command down}
                click pop up button 1 of window 1
                click menu item "WPA2 Enterprise" of menu 1 of pop up button 1 of window 1
                delay 1
                click pop up button 2 of window 1
                click menu item "Automatic" of menu 1 of pop up button 2 of window 1
                delay 1
                set the clipboard to myAcct
                click text field 1 of window 1
                keystroke "v" using {command down}
                delay 1
                set the clipboard to myPass
                keystroke tab
                keystroke "v" using {command down}
                delay 1
                click button "Add" of window 1
                
                -- Setup WEP network 
                
                do shell script "/tmp/yourfolder/BigHonkingText -M -p 2 -b orange \"     Please DO NOT TOUCH, be patient.     \""
                click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
                set the clipboard to WEPNameString
                click text field 1 of group 1 of window 1
                keystroke "v" using {command down}
                click pop up button 1 of window 1
                click menu item "WEP Password" of menu 1 of pop up button 1 of window 1
                set the clipboard to WEPPassString
                keystroke "v" using {command down}
                delay 1
                click button "Add" of window 1
                click button "OK" of sheet 1 of window "Network"
                keystroke myMacPass
                keystroke return
                set the clipboard to ClearClipboardString
                delay 2
                click button "Apply" of window "Network"
            end tell
        end tell
        
    end tell
    
    -- Add the certificate to the keychain
    do shell script "certtool i /path/to/your/certificate/tigernet.clemson.edu.pem k=/Users/$USER/Library/Keychains/login.keychain" user name theUser password myMacPass with administrator privileges
    
    -- Setup permissions on the certificate
    tell application "Keychain Access"
        activate
        tell application "System Events"
            tell application process "Keychain Access"
                delay 2
                keystroke CertName
                keystroke tab
                keystroke tab
                keystroke tab
                keystroke "i" using {command down}
                delay 1
                click checkbox 1 of scroll area of window "name.of.your.certificate"
                delay 1
                click pop up button 4 of scroll area of window "name.of.your.certificate"
                keystroke "a"
                keystroke return
                delay 0.5
                click pop up button 10 of scroll area of window " name.of.your.certificate"
                keystroke "a"
                keystroke return
                delay 0.5
                do shell script "/tmp/yourfolder/BigHonkingText -M -p 2 -b orange \"     Please DO NOT TOUCH, be patient.     \""
                click button 1 of window "name.of.your.certificate"
                keystroke myMacPass
                keystroke return
                delay 1
                tell application "Keychain Access" to quit
            end tell
        end tell
    end tell
    
    -- Connect to wireless
    do shell script "networksetup -setairportpower on"
    delay 1
    tell application "System Preferences" to quit
    display dialog "Wireless Setup Is Complete! Please click the 'OK' button." buttons {"OK"} default button 1
    
    
on error
    display dialog "Wireless setup failed! Please call Jenny at 867-5309 for more help."
    
end try

Are you guys using a more current version of BigHonkingText than I am? I got mine here:

http://macenterprise.org/content/view/223/129/

But it claims not to understand the -H and -d flags in your script. Any suggestions?

Thanks!

@homepup

Thanks for posting this. Modified it to work with our WPA Personal network, and built a Tiger-operable version that basically employs a lot of GUI scripting, and relies on the user to power the AP card off and back on, since there’s no reliable way to automate that.

Be happy to post the script if anyone’s interested, but it’s substantially the same as yours, minus some of the password requests.

Cool deal. I’d like to see what you came up with since we still had a few minor issues with ours and had to do some more tweaks. I also found a command-line method for the entire certificate part that will add the certificate to the System.keychain and set it to trusted for all users on all policies which is fine since it is our certificate. This version has been tested to work fairly well with 10.5.3 and has a final dialog that has to be manually clicked on in 10.5.2. It’s still very fragile though and requires that the user hasn’t already been set up to the network previously and types the correct password info. I’ll be making some more tweaks to it this week probably to add some error reporting for when something breaks (like a bad password).

I’d also like to add a piece that checks the username and password for the network setup against our ldap server before continuing the script. You’d be surprised how many people can’t type their passwords right the first try which makes it crumble.

I got my version of BigHonkingText direct from an Apple engineer. Might be a new version being worked up.

There are still some parts of the script that are relying on certain parts to have been installed in /tmp/somefolder by an installer beforehand, like BigHonkingText and the certificate to install in the keychain.

I’ve also got some parts that reset the wireless, so you might want to look at that too.

set CertName to "your.cert"
set WPANameString to "your.wpa.network"
set WEPNameString to "your.wep.network"
set WEPPassString to "your.wep.password"
set ClearClipboardString to "something to overwrite the password info later on"
set theUser to (do shell script "echo $USER")

try
	tell current application
		activate
		set acctBox to display dialog "Wireless Connection Setup:
Please enter your network USERNAME
(Ex. USERNAME@mydomain.com)" default answer "" buttons {"Cancel", "OK"} default button 2
		set myAcct to the text returned of acctBox
		set myButton to the button returned of acctBox
		if myButton is "OK" then
			if myAcct is not "" then
				set myPass to display dialog "Please enter your network password: Be careful to enter it correctly!" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
				if myPass is not "" then
					set myMacPassDialog to display dialog "Please carefully enter your Mac/Apple password. (This is the password you used to start the installer)" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
					set myMacPass to the text returned of myMacPassDialog
				else
					RestartRoutine()
				end if
			else
				RestartRoutine()
			end if
		else
			RestartRoutine()
		end if
		
		if myAcct contains "@" then
			set myAcct to text 1 through ((offset of "@" in myAcct) - 1) of myAcct
		end if
		
		
		set acctBox to display dialog "Click OK to install then please DO NOT TOUCH the keyboard or mouse/trackpad until wireless setup is complete!" buttons {"Cancel", "OK"} default button 2
		set myButton to the button returned of acctBox
		if myButton is "Cancel" then
			quit
		end if
	end tell
	
	-- MUST Turn off wireless 
	do shell script "networksetup -setairportpower off" user name theUser password myMacPass with administrator privileges
	
	-- MUST Turn on Assistive Devices for script to run properly
	do shell script "sudo touch /private/var/db/.AccessibilityAPIEnabled" user name theUser password myMacPass with administrator privileges
	
	tell application "System Preferences"
		activate
		set the current pane to pane id "com.apple.preference.network"
		get the name of every anchor of pane id "com.apple.preference.network"
		reveal anchor "Advanced Airport" of pane id "com.apple.preference.network"
		try
			tell application "System Events"
				tell application process "System Preferences"
					-- Setup WPA2 network 
					do shell script "/tmp/somefolder/BigHonkingText -M -p 2 -b orange \"     Please DO NOT TOUCH, be patient.     \""
					click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
					set the clipboard to WPANameString
					click text field 1 of group 1 of window 1
					keystroke "v" using {command down}
					click pop up button 1 of window 1
					click menu item "WPA2 Enterprise" of menu 1 of pop up button 1 of window 1
					delay 1
					click pop up button 2 of window 1
					click menu item "Automatic" of menu 1 of pop up button 2 of window 1
					delay 1
					set the clipboard to myAcct
					click text field 1 of window 1
					keystroke "v" using {command down}
					delay 1
					set the clipboard to myPass
					keystroke tab
					keystroke "v" using {command down}
					delay 1
					click button "Add" of window 1
					
					-- Setup WEP network 
					
					do shell script "/tmp/somefolder/BigHonkingText -M -p 2 -b orange \"     Please DO NOT TOUCH, be patient.     \""
					click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
					set the clipboard to WEPNameString
					click text field 1 of group 1 of window 1
					keystroke "v" using {command down}
					click pop up button 1 of window 1
					click menu item "WEP Password" of menu 1 of pop up button 1 of window 1
					set the clipboard to WEPPassString
					keystroke "v" using {command down}
					delay 1
					click button "Add" of window 1
					click button "OK" of sheet 1 of window "Network"
					keystroke myMacPass
					keystroke return
					set the clipboard to ClearClipboardString
					delay 2
					click button "Apply" of window "Network"
					delay 1
				end tell
				
			end tell
		on error
			display dialog "Network settings error"
		end try
	end tell
	
	-- Add the certificate to the keychain
	try
		do shell script "sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain /private/tmp/some_folder/your.certificate.pem" user name theUser password myMacPass with administrator privileges
		delay 1
	on error
		display dialog "Could not load certificate"
	end try
	-- Connect to wireless
	do shell script "networksetup -setairportpower on"
	delay 1
	tell application "System Preferences" to quit
	do shell script "/tmp/somefolder/BigHonkingText -M -p 4 -b orange \"     Wireless Setup Is Complete!     \""
	
	
on error
	display dialog "Wireless setup failed! Please call Jenny at 867-5309 for more help."
	
end try

I’ll post my scripts later today or tomorrow. I need to do some final testing. I also need to see if I’m able to write in some kind of error trap that removes previous setups with the same name. But that’s not critical until next year. :slight_smile: And I want to read over what you just posted and see what I can roll in.

In the meantime, I found the download link for BigHonkingText. It’s on Steve Hayman’s iDisk…follow the Files link.

http://homepage.mac.com/shayman

WRT the installer requirement, I just ginned up a package that dumps all the tools in the right places. The user is the responsible to run the actual setup script. I think the only other major difference is that where you rely on a cert, we distribute a shared secret key. I just have that written into the script, which is then saved as run-only. Since the user can view the key once it’s installed anyway, we didn’t place a huge amount of emphasis on keeping it s00per-seekrit.

Further testing revealed a number of problems. Not least of which is that unzipping the saved-as-applications scripts from the command line (either by postflight script or by the action of Installer) hosed them. They kept trying to open in Classic. Not having an immediate solution, I reverted to distribution by DMG. This turns out to have been a better proposition, in that I simply place BigHonkingText and our network cert in a hidden directory on the installer, and they’re called as needed from there. I’d love any feedback on this script for Tiger, as it’s particularly ugly, though it does work.

These are saved as run-only scripts to provide a modicum of protection for the shared key (among other reasons).

-- [snipped obligatory legalese]

set wpaName to "yourNetworkName"
set WPAPass to "yourSharedSecret "
set clearClip to "someText"
set userName to (do shell script "echo $USER")

try
	tell current application
		activate
		set acctBox to display dialog "Wireless Connection Setup:
Please enter your computer password
(Your password for THIS machine, not your INSTITUTION password)" default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
		set macPass to the text returned of acctBox
	end tell
	
	-- Enable Assistive Devices. Script will fail if this is not enabled!
	try
		do shell script "touch /private/var/db/.AccessibilityAPIEnabled" with administrator privileges
	end try
	
	-- Alert user to disable wireless. CLI tools are unreliable under Tiger, as is GUI scripting.
	do shell script "say 'To continue setup you must enable your airport card'"
	do shell script "say 'Please turn on your wireless card using these instructions'"
	display dialog "To make this setup script work under OS X 10.4, you must enable AirPort!
	
To do this, click the AirPort icon in your menu bar (above right, looks like a wedge), and choose 'Turn AirPort On' (if it says 'Turn AirPort Off' then Airport is already enabled). The icon will change to a fan. If you do not do this, setup will fail!
	
Click OK only after you have turned AirPort on."
	
	do shell script "say 'Please do not touch the keyboard or mouse while setup is running'"
	do shell script "/Volumes/DiskImageName/.hiddendirectory/BigHonkingText -M -p 5 -b red \" DO NOT TOUCH! Be patient. \""
	
	--This part of the process is GUI-scripted, and it probably brittle.
	tell application "System Preferences"
		activate
		set the current pane to pane id "com.apple.preference.network"
		tell application "System Events"
			tell application process "System Preferences"
				-- Configure WPA settings
				click pop up button 2 of window "Network"
				delay 1
				click menu item "AirPort" of menu 1 of pop up button 2 of window 1
				delay 1
				click pop up button 1 of group 1 of tab group 1 of group 1 of window "Network"
				click menu item "Preferred networks" of menu 1 of pop up button 1 of group 1 of tab group 1 of group 1 of window "Network"
				delay 1
				click button 2 of group 1 of tab group 1 of group 1 of window "Network"
				delay 1
				keystroke wpaName
				delay 1
				click pop up button 1 of sheet 1 of window "Network"
				click menu item "WPA Personal" of menu 1 of pop up button 1 of sheet 1 of window "Network"
				delay 2
				keystroke tab
				set the clipboard to WPAPass
				click text field 1 of sheet 1 of window "Network"
				keystroke "v" using {command down}
				delay 2
				keystroke return
				delay 1
				keystroke macPass
				delay 1
				keystroke return
				set the clipboard to clearClip
				delay 2
				click button "Apply Now" of window "Network"
			end tell
		end tell
	end tell
	
	--Open the security cert from a hidden directory on the DMG and install it to the X509Anchors keychain
	do shell script "open /Volumes/DiskImageName/.hiddendirectory/huey.pem"
	delay 2
	tell application "System Events"
		tell application process "Keychain Access"
			delay 1
			click pop up button 1 of window "Add Certificates"
			delay 1
			click menu item "X509Anchors" of menu 1 of pop up button 1 of window "Add Certificates"
			delay 1
			click button "OK" of window "Add Certificates"
			delay 2
			keystroke macPass
			delay 5
			keystroke return
		end tell
	end tell
	tell application "Keychain Access"
		quit
	end tell
	
	--Notify the user that we're done.
	do shell script "/Volumes/DiskImageName/.hiddendirectory/BigHonkingText -M -p 5 -b red \" Setup complete! \""
	do shell script "say 'You may use your keyboard and mouse again'"
	do shell script "say 'YOURNETWORK is now configured on your computer'"
	display dialog "Wireless setup is complete and you are permitted to use your keyboard and mouse again.
	
If you are not automatically connected to YOURNETWORK, open the AirPort menu bar icon and select YOURNETWORK to connect. 

Please click the 'OK' button." buttons {"OK"} default button 1
	
	display dialog "For best compatibility, you should import the security certificate on your desktop into your Mac's keychain. Please consult the Readme file on DiskImageName disk for instructions."
	
on error
	display dialog "Wireless setup failed! Please contact ResNet or the Help Desk (as appropriate) for more help."
	
end try

Hopefully, I’ll have the Leopard script finished off tomorrow, and I’ll post it. The one thing I wasn’t able to do, unfortunately, is to autoinstall the Clean Access Agent we require. Though as I’m typing this, it occurs that I could do that by calling the installer silently from AppleScript! Hah. Another mod, but I’ll hold that until the other material is done.

Is there a way to accomplish this with no user interaction? I am in a situation where I have to probably migrate thousands of Mac clients to a WPA solution, and keychain is a pain. I want to shell script it but am open to apple scripts if this can be done with out the user having any interactions with it.

Could you possibly post the packmaker build you created for this? I would be so appreciative. I am trying to create a build of this that uses the BigHonkingText and the applescript in one application, and I am not having much luck. I am trying to set up 100+ laptops for an elementary school.
Thanks,
Paul
pallen@csusb.edu

Hi guys,

I have modify the script in the topic to suit my needs and it is work generally but needs some minor tweaks. Basically i work for a college and we wish to push this script package with automator to help new students setup college wireless alot more easier rather than standing in liner for support. I have no experience in applescript or mac so basically i just play with the code cutting or editing line by line until its somewhat working. I have been trying almost everything i can think out without success so any help will be appriciated.

There is two problems that i am stuck with right now and i hope you guys can help:

  1. if a laptop has not been run with the script, it will prompt for the password of the laptop. It will then process until the advance panel of airport but it will stop there. It will not press “+” button and type in the wireless name. If i close the script and re-run it, it will prmopt for the password of the laptop and continue on to complete the entire process. This is a problem since we will basically use this program once for every student assuming they dont delete the wireless configuration, but having the need to re-launch the program will discourage the students from using the program.

  2. when the script executes properly, it will load the window to type in the wireless name but it will pause of 5 to 6 seconds before typing in the wireless name. I remove the delay 1 in the script but the probem is still there.

on run {input, parameters}
	
	set wpaName to "CollegeSecureWLAN"
	
	try
		do shell script "touch /private/var/db/.AccessibilityAPIEnabled" with administrator privileges
	end try
	
	tell application "System Preferences"
		activate
		set the current pane to pane id "com.apple.preference.network"
		reveal anchor "Advanced Airport" of pane id "com.apple.preference.network"
		tell application "System Events"
			tell application process "System Preferences"
				-- Configure WPA settings
				click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
				delay 1
				keystroke wpaName
				delay 1
				click pop up button of window 1
				delay 1
				click menu item "WPA2 Enterprise" of menu 1 of pop up button 1 of window 1
				delay 1
				click button "Add" of window 1
				delay 1
				click button "OK" of sheet 1 of window 1
				delay 1
				click button "Apply" of window "Network"
				delay 1
			end tell
		end tell
		quit
	end tell
	
	return input
end run

Can anyone help? I have not been able to get the script working without failing for the first time. Kinda strange that it will run on second try.

paulmattallen,

I have mine included as part of a Packagemaker installer .pkg that dumps the payload to a /tmp/folder. Then a postscript engages the applescript app (actually, keep it in a .dmg which decompresses as part of the postscript after dumping the payload). Also included iHook (prefer that over BigHonkingText) to give some user feedback and block user interaction somewhat.

howewong,

I think what might be happening is that the step that turns on Accessibility (do shell script “touch /private/var/db/.AccessibilityAPIEnabled” with administrator privileges) needs a second to do it’s thing before System Prefs opens. Try throwing a delay in between there and see if it helps.

I’m posting my main applescript without the iHook parts (since it would have to have those installed in the correct location to run). Hoping to add an uninstaller at the beginning to cleanup any existing clutter from a bad previous setup one day, but it’s proving to be quite difficult.

This script originally contained several dialog boxes that prompted the user about what was going on. Those were removed when I added iHook as the feedback mechanism for the user.

set CertName to "name_of_certificate"
set WPANameString to "name_of_wpa_network"
set ClearClipboardString to "Insert easter egg here"
set theUser to (do shell script "echo $USER")
set myMacPassTest to ""
set myPass to ""
set counter to 1
set previousSetup to ""

-- use GUI to set password - this creates an entry in the system keychain, with the airport plist and sets up permissions on the certificate

try
	tell current application
		activate
		repeat until myMacPassTest is not ""
			set myMacPassDialog to display dialog "Please enter your Mac/Apple password. (This is the password you used to start the installer)" default answer "" buttons {"Cancel", "OK"} default button 2 with title "YOUR_BUSINESS Wireless Setup" with hidden answer
			set myMacPass to the text returned of myMacPassDialog
			
			-- Test to see if Mac Password is correct
			try
				do shell script "sudo touch /private/tmp/mac_password_test" user name theUser password myMacPass with administrator privileges
				set myMacPassTest to "true"
			on error
				display dialog "Mac Password entered was incorrect, please try again." with title "YOUR_BUSINESS Wireless Setup" with icon caution
				set myMacPassTest to ""
			end try
		end repeat
		
		-- cleanup password test file
		do shell script "sudo rm -rf /private/tmp/mac_password_test" user name theUser password myMacPass with administrator privileges
		
		
		try
			tell current application
				activate
				set previousSetup to do shell script "defaults read /Library/Preferences/SystemConfiguration/preferences | grep name_of_wpa_network"
				if previousSetup is not "" then
					display dialog "WARNING!!! A previous name_of_wpa_network connection was detected!" & return & return & "Please contact a support person to help clear the previous settings before continuing with the wireless installation." & return & return & "The wireless connection SSID, 802.1x user profile, Keychain entry and certificate must all be removed before continuing!" & return & return & "If a support person is unavailable, please click QUIT and call 867-5309" buttons {"QUIT"} default button 1 with title "YOUR_BUSINESS Wireless Setup" with icon caution
					do shell script "sudo killall setup_wireless.app" user name theUser password myMacPass with administrator privileges
				end if
			end tell
		end try
		
		-- MUST Turn off wireless 
		do shell script "networksetup -setairportpower off" user name theUser password myMacPass with administrator privileges
		
		-- MUST Turn on Assistive Devices for script to run properly
		do shell script "sudo touch /private/var/db/.AccessibilityAPIEnabled" user name theUser password myMacPass with administrator privileges
		
		repeat until myPass is not ""
			if counter < 4 then
				set acctBox to display dialog "Please enter your USERNAME" & return & "(Ex. USERNAME@business.com)" default answer "" buttons {"Cancel", "OK"} default button 2 with title "YOUR_BUSINESS Wireless Setup"
				set myAcct to the text returned of acctBox
				set myButton to the button returned of acctBox
				if myButton is "OK" then
					if myAcct is not "" then
						
						-- Remove any trailing @mydomain.com information from network name
						if myAcct contains "@" then
							set myAcct to text 1 through ((offset of "@" in myAcct) - 1) of myAcct
						end if
						
						-- Test to see if Network password is correct
						set myPassBox to display dialog "Please enter your network password:" & return & return & "Be careful to enter it correctly!" & return & "This password is case-sensitive!" default answer "" buttons {"Cancel", "OK"} default button 2 with title "YOUR_BUSINESS Wireless Setup" with hidden answer
						set myPass to the text returned of myPassBox
						
						-- Test to see if Network Password is correct
						try
							do shell script "sudo mkdir '/Volumes/Share'" user name theUser password myMacPass with administrator privileges
							do shell script "sudo mount_smbfs '//" & myAcct & ":" & myPass & "@share/Share' /Volumes/Share/" user name theUser password myMacPass with administrator privileges
						on error
							do shell script "sudo rmdir /Volumes/Share/" user name theUser password myMacPass with administrator privileges
							set myPass to ""
							if counter < 3 then
								display dialog "Password entered was incorrect, please try again." with title "YOUR_BUSINESS Wireless Setup" with icon caution
							end if
						end try
					else
						display dialog "Business username can not be blank!" with icon caution
					end if
				end if
			else
				display dialog "Password is not accepted. Please click cancel, reset your password and try again." buttons {"Cancel", "OK"} default button 1 with icon caution
				set myPass to "exit loop"
				do shell script "sudo killall setup_wireless.app" user name theUser password myMacPass with administrator privileges
			end if
			set counter to counter + 1
		end repeat
		delay 2
		try
			do shell script "sudo umount /Volumes/Share/" user name theUser password myMacPass with administrator privileges
		on error
			
			display dialog "Could not disconnect network drive during network password test"
			do shell script "sudo killall setup_wireless.app" user name theUser password myMacPass with administrator privileges
			
		end try
		
		
	end tell
	
	tell application "System Preferences"
		activate
		set the current pane to pane id "com.apple.preference.network"
		get the name of every anchor of pane id "com.apple.preference.network"
		reveal anchor "Advanced Airport" of pane id "com.apple.preference.network"
		try
			tell application "System Events"
				tell application process "System Preferences"
					-- Setup WPA2 network called name_of_wpa_network
					click button 1 of group 1 of tab group 1 of sheet 1 of window "Network"
					set the clipboard to WPANameString
					click text field 1 of group 1 of window 1
					keystroke "v" using {command down}
					click pop up button 1 of window 1
					click menu item "WPA2 Enterprise" of menu 1 of pop up button 1 of window 1
					delay 1
					click pop up button 2 of window 1
					click menu item "Automatic" of menu 1 of pop up button 2 of window 1
					delay 1
					set the clipboard to myAcct
					click text field 1 of window 1
					keystroke "v" using {command down}
					delay 1
					set the clipboard to myPass
					keystroke tab
					keystroke "v" using {command down}
					delay 1
					click button "Add" of window 1
					click button "OK" of sheet 1 of window "Network"
					keystroke myMacPass
					keystroke return
					set the clipboard to ClearClipboardString
					delay 2
					click button "Apply" of window "Network"
					delay 1
					
				end tell
				
			end tell
		on error
			
			display dialog "Network settings error"
			do shell script "sudo killall setup_wireless.app" user name theUser password myMacPass with administrator privileges
			
		end try
	end tell
	
	-- Add the certificate to the keychain
	try
		do shell script "sudo security add-trusted-cert -d -r trustAsRoot -k /Library/Keychains/System.keychain /private/tmp/cu_wireless/name_of_certificate.pem" user name theUser password myMacPass with administrator privileges
		delay 1
	on error
		
		display dialog "Could not load certificate"
		do shell script "sudo killall setup_wireless.app" user name theUser password myMacPass with administrator privileges
		
	end try
	-- Connect to wireless
	do shell script "networksetup -setairportpower on"
	delay 3
	do shell script "networksetup -setairportpower off"
	delay 3
	do shell script "networksetup -setairportpower on"
	delay 1
	tell application "System Preferences" to quit
	
on error
	
	display dialog "Wireless setup failed! Please contact your support person or call 867-5309 for more help."
	
end try

Ok, after making the previous versions (and possibly some others in between), here’s my final version that we are using at our University. It is a combination of Applescript, Shell script and python (only one line). If you find it useful, please let me know and I want to thank everyone that helped with it.

http://bigmaconcampus.wordpress.com/2009/03/25/wireless-installer-for-the-masses/