To find out the name of the menu items, you need a tool called UIElementInspector, or the newer Accessibility Inspector, which can be found here:
/Developer/Applications/Utilities/Accessibility Tools/Accessibility Inspector.app
... if you have the latest developer tools installed. I can't find a simple download link of UIElementInspector, but its available as sample code to compile yourself, which again would require developer tools installed.
These tools display the names of all the menus, menu items, buttons, etc to let you write UI Applescripts. You just mouse over a UI element anywhere on the screen and it shows you all the details in a window.
I don't have wireless on this mac, so can't get the names of the menu for you.
I've done one for Bluetooth which works for me here on Snow Leopard 10.6.6:
Code:
tell application "System Events"
tell process "SystemUIServer"
tell menu bar 1
set menuExtras to (value of attribute "AXChildren")
tell menuExtras
set bluetooth to (first item whose (value of attribute "AXDescription") contains "bluetooth")
end tell
tell bluetooth
perform action "AXPress"
tell menu 1
if name of menu item 1 ends with "Off" then
click menu item "Turn Bluetooth On"
else
-- just close the menu if Bluetooth is already on
tell bluetooth to perform action "AXPress"
end if
end tell
end tell
end tell
end tell
end tell
Which is taken from coolsoldier's post here:
http://hints.macworld.com/article.php?story=20060921045743404
Edit:
Ok, tried this on an iBook with 10.4.11 Tiger and it works to turn Airport on. Selecting a network would require you to know the name of it and I'll leave that up to you.
Code:
tell application "System Events"
tell process "SystemUIServer"
tell menu bar 1
set menuExtras to (value of attribute "AXChildren")
set airport to -1
repeat with aMenu in menuExtras
tell aMenu
if value of attribute "AXDescription" contains "AirPort Menu Extra" then
set airport to aMenu
exit repeat
end if
end tell
end repeat
if airport is -1 then
display dialog "Could not find AirPort Menu Extra"
else
tell airport
perform action "AXPress"
tell menu 1
if name of menu item 1 ends with "Off" then
click menu item "Turn Airport On"
else
-- just close the menu if airport is already on
tell airport to perform action "AXPress"
end if
end tell
end tell
end if
end tell
end tell
end tell