Airport Restarter Applescript

Discussion in 'Mac Programming' started by Nemefist, Dec 30, 2007.

  1. Nemefist macrumors newbie

    Dec 30, 2007
    Alright heres the deal. I play an online game and am suffering from random internet freezes that require me to manually click on the Airport Icon and reconnect to my network in order to continue playing. I am looking for an apple script compatible with the Airport UI for the 10.5 OS X which pings my internet connection at certain time intervals and then and restarts the airport if a drop has happened. I found an applescript that would work, but it is for the 10.4 OS X. It is not friendly with the new UI of Leopard's Airport Utility. Basically I need a translation of this 10.4 script to become a 10.5 compatible script. I'm not very skilled in Applescript so I cannot do it myself. Please help.

    Heres the script:

    do shell script "sleep 300"
    end repeat

    on restartIfNecessary()
    set s to "ping -c 1 -t 4 > /dev/null; echo $?"
    set r to do shell script s

    if r is equal to "0" then
    dlog(((current date) as string) & " AirPort OK")
    dlog(((current date) as string) & " AirPort down. Restarting.")
    end if
    end restartIfNecessary

    on restartAirPort()
    tell application "AppleScript Utility"
    delay 2
    tell application "System Events"
    tell window 1 of process "Internet Connect"
    tell button "AirPort" of tool bar 1 to click
    delay 2
    end try

    tell button "Turn AirPort Off" to click
    delay 7
    end try

    tell button "Turn AirPort On" to click
    delay 2
    on error
    tell button "Turn AirPort Off" to click
    end try
    end try
    end tell
    end tell

    end tell
    end restartAirPort

    on dlog(msg)
    set t to ((path to temporary items) as string) & "AirPortRestarter.log"
    set f to open for access file t with write permission

    write msg & "
    " to f starting at (get eof of f) + 1

    close access f
    end dlog


    I did not make this script, nor do I take credit for any part of this. Please help me with my issue!
  2. Consultant macrumors G5


    Jun 27, 2007
    Did you update the Airport firmware? What about using ethernet cable?
  3. Nemefist thread starter macrumors newbie

    Dec 30, 2007
    Ethernet is not an option and yes, i did update it. I've tried everything but this, and this seems to be the only reasonable solution.
  4. LtRammstein macrumors 6502a


    Jun 20, 2006
    Denver, CO
    First off, Leopard doesn't have Internet Connect anymore, it was a really pointless program to begin with.

    Secondly, you would have to get it so it's in System Preferences. The restartAirport() function is really poorly written for what you want, because no matter what, if an error occurs (I can't figure out what kind of error), it will keep Airport turned off, which is a nice safety feature, but not necessary. Now are you turning off Airport card from your computer off, or the base station/express?

    Third, what would be the point of keeping a log of when it goes down? The only time it should go down is if what you are requesting in a game is far more than what the base station can handle.

    It would be best to ask the author of the script to update it for Leopard, or learn it yourself (which I recommend since AppleScript is really quite easy to understand).
  5. aforty macrumors 65816


    Nov 27, 2007
    Brooklyn, NY
    Did you post this one every Mac/WoW form you could find and pollute Google? Thanks.

    If you get random disconnects look into getting a new router.

Share This Page