Airport Toggle with password. Best method?

I did a search on this and actually found too much info on here, so I need help sorting it out.

I want to toggle my MBP Airport off, then on again. But I require the admin password for each step (otherwise, my laptop is constantly jumping to the wrong network, despite my best efforts).

  1. Is there a way to do it without having to save my password in the script, or turn off the password requirement?
  2. Is the best method an Applescript, or Automator?

Thanks

It might be useful to know more about the statement above – Why?

Network1 (Location A): Public/Unprotected/Unlimited
Network2 (Location B): Semi-Private/Protected/Semi-Limited
Network3 (Mobile, locations A&B): Private/Protected/Crazy-Limited

So I use all I want on Network1, but it’s public, and unsafe for personal use. When I do personal things I switch back to Network3. If I don’t have this password protected (changing airport settings), then I kept catching it switching without telling me if either lost a connection.

I don’t pay for Network2, so I don’t want to do download too much on it and stick them with a huge bill for MY use. If I know they are near their limits, or I will be pushing lots of download, I switch back to Network3. Again, Airport keeps switching without my permission if not restricted by password.

Finally, Network3 is mobile, and a bit unstable. So if I notice a timeout, I usually toggle on/off and it reconnects at full speed again. However, the toggle would still be helpful for the first two.

Gotcha – and I see why this is a problem too; the AirPort Utility’s Dictionary is generic – nothing to grab. AirPort is configured in /Library/Application Support/Apple/AirPort/, but I haven’t sorted that out. Your best bet is to GUI script the “Turn AirPort Off”/“Turn AirPort On” button on the Network pane of System Preferences.

Which brings me back to the original questions: Can it be done without leaving my password viewable in the script, and do I use AS or Automator?

If you please…

Some fiddling with the menu bar item # may be needed, and for all of that, this is only tested on 10.4.11, but I’m toggling Airport on and off from the menu bar with the script below.

If whatever script you use results in a dialog for password entry, you could always thoroughly obfuscate the actual password in the script and save it as run-only besides.

But I admit, I may be wide of the mark here.

By the way, I can also get the value of the menu bar item using the second script below… which allows an ‘informed’ if/then choice.

Peter B.



tell application "SystemUIServer" to activate

tell application "System Events"
	
	tell process "SystemUIServer"
		
		click menu bar item 1 of menu bar 1
		
	end tell
	
	delay 0.5
	
	keystroke (ASCII character 31)
	keystroke (ASCII character 3)
	
end tell


tell application "SystemUIServer" to activate

tell application "System Events"
	
	tell process "SystemUIServer"
		
		get value of menu bar item 1 of menu bar 1
		
	end tell
	
end tell