Automating the creation of a 128-bit WEP AirPort network

I was looking for a way to automate my WEP setup to use with my iPhone, and found a script from 2008 that got me 80% of the way there. Inspiration from a posting on 2008-06-04 by “homepup” at http://macscripter.net/viewtopic.php?id=25717.

Unlike the original poster, instead of a one-time setup when the Mac is deployed, this script should be run when the machine is restarted or the network has gone missing.

Written on and for Mac OS X 10.6.8, compatibility with Lion is unknown at this point :wink:

The network needs to be created with Airport ON, and directly in the Airport (not Advanced Airport) pane. It also accesses several popup menus to get to the 128-bit WEP version.

The Accessibility Inspector in Developer Tools was invaluable for writing this script!

FYI, running with the network already operating isn’t a problem, so I didn’t add any existence checks. I also removed the certificate as it only needs to be done once, and wasn’t worth fixing for my application.

Here’s my modified version. Any tales of woe or triumph are appreciated.


-- Create 128-bit WEP network.scpt
-- Modified 2012-02-03 D. Zurn
-- Inspiration from a posting on 2008-06-04 by "homepup" at http://macscripter.net/viewtopic.php?id=25717

-- Name for the WEP network
set WEPNameString to "MyWEPNetwork"

-- The 128-bit WEP password. Must be exactly 13 characters!
set WEPPassString to "MyWEPPassWord"

set ClearClipboardString to "any bit of text to clear the clipboard"
set theUser to (do shell script "echo $USER")

try
	tell current application
		activate
		set myMacPassDialog to display dialog "Please enter your Mac password." default answer "" buttons {"Cancel", "OK"} default button 2 with hidden answer
		set myMacPass to the text returned of myMacPassDialog
		
	end tell
	
	-- AirPort must be ON to create network
	do shell script "networksetup -setairportpower AirPort on" 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 "AirPort" of pane id "com.apple.preference.network"
		
		tell application "System Events"
			tell application process "System Preferences"
				-- Setup WEP network
				
				-- do shell script "/tmp/yourfolder/BigHonkingText -M -p 2 -b orange \" Please DO NOT TOUCH, be patient. \""
				click pop up button 1 of group 1 of window "Network"
				click menu item "Create Network." of menu 1 of pop up button 1 of group 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 checkbox "Require Password" of sheet 1 of window "Network"
				keystroke tab
				
				set the clipboard to WEPPassString
				keystroke "v" using {command down}
				keystroke tab
				keystroke "v" using {command down}
				
				tell sheet 1 of window "Network"
					click pop up button "Security:"
					click menu item "128-bit WEP" of menu 1 of pop up button "Security:"
					click button "OK"
				end tell
				
			end tell
		end tell
		
	end tell
	
	delay 3
	tell application "System Preferences" to quit
	
on error
	display dialog "Wireless setup failed! Please call Jenny at 867-5309 for more help." buttons {"OK"} default button 1
end try

Model: Mac Pro Intel
AppleScript: 2.1.2
Browser: Firefox 10.0
Operating System: Mac OS X (10.6)

Hi,

if the name and the phone number are real, I recommend to remove them

They aren’t real. The name and phone # are from an old top-40’s pop song!

http://www.snopes.com/music/songs/8675309.asp