Need Apple Script Direction - Disconnect/Reconnect Wifi

Discussion in 'Mac Programming' started by OSXC, Apr 4, 2017.

  1. OSXC macrumors newbie

    OSXC

    Joined:
    Apr 4, 2017
    Location:
    Los Angeles
    #1
    Hi guys,

    I'm trying to find a script or write one that will allow me to set the following condition:

    If the Tx Rate of *My SSID* is less than 100, disconnect from *My SSID* then reconnect to *My SSID*

    Not sure how to start, was going to use automator, but felt like it would be more effective via AS.
     
  2. Kornelis, Apr 6, 2017
    Last edited: Apr 6, 2017

    Kornelis macrumors member

    Kornelis

    Joined:
    Dec 4, 2010
    Location:
    Amsterdam, NL
    #2
    You can also use AppleScript in Automator.

    To determine the Tx Speed of the Access Point you are connected to and if it is lower than 100 disconnect and reconnect:

    Code:
    set TxRate to do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I|grep lastTxRate|sed \"s/[^[:digit:]]//g\""
    
    --check if Mac is connected
    try
        set LinkActive to word 2 of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport -I |grep state  ")
    on error
        set LinkActive to "disconnected"
    end try
    
    if TxRate < 100 and LinkActive = "running" then
        --To switch off Wi-Fi (in my case the Wi-Fi adapter is en0):
        do shell script "networksetup -setairportpower en0 off" with administrator privileges
        --Switch Wi-Fi back on:
        do shell script "networksetup -setairportpower en0 on" with administrator privileges
    end if
    
     

Share This Page