Airport Restarter Applescript

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

  1. Nemefist macrumors newbie

    Joined:
    Dec 30, 2007
    #1
    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:

    ----------------------------------------------------------------------------------------------------------------------------
    repeat
    restartIfNecessary()
    do shell script "sleep 300"
    end repeat


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

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

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

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

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

    quit
    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

    Consultant

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

    Joined:
    Dec 30, 2007
    #3
    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

    LtRammstein

    Joined:
    Jun 20, 2006
    Location:
    Denver, CO
    #4
    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

    aforty

    Joined:
    Nov 27, 2007
    Location:
    Brooklyn, NY
    #5
    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