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)