Why doesn't this method of restarting airport work?

I’m writing a script designed to reconnect to a specified wireless network at a certain time. I must first disconnect from the network and then reconnect. This can be done by turning airport power off and back on, but i also had the hope that it could be done with “disconnect” and “reconnect” commands. I’ve bundled together a lot of other script ideas and came up with the following. I would like to know why it doesn’t work.

tell application "Finder"
	set getTheIP to "networksetup -getinfo airport | awk '/address/ && !/IPv6/ {print $3}'"
	set getTheWiFi to "/usr/sbin/networksetup -getairportnetwork airport | awk  '{print $4}'"
	set theWiFi to (do shell script getTheWiFi)
end tell

tell application "System Events"
	disconnect theWiFi
	delay 2
end tell

--the following determines the IP address so that i can know if it truly disconnected or not.  this always returns an address, though, so i conclude that the command is not working
do shell script getTheIP

tell application "System Events"
	connect theWiFi
	delay 4
end tell

I suspect that someone will ask, so this is the “off-on” set of commands for airport that do this successfully. I just wanted to find a way that didn’t make me need to have the script make sure it’s connected to the correct network (i hope that all made sense).

do shell script "/usr/sbin/networksetup -setairportpower off"
do shell script "/usr/sbin/networksetup -setairportpower on"

Operating System: Mac OS X (10.5)

Notice in the System Events dictionary that it is disconnect anything. I agree that the disconnection doesn’t happen if anything is the name of the AirPort connection, but don’t know what it should be.

As a workaround I would use, you might try setting up two different locations and switch between them.

I think i see what you mean about the “anything”. There would need to be something in that variable that tells System Events that a network is the target. Maybe there’s a better way that doesn’t involve system events.

Anyone know of a shell script that will merely disconnect from a network instead of turning off airport?

Also, your workaround idea is clever, but doesn’t work for the intended use of this script, unfortunately.