Last active
November 2, 2019 17:46
-
-
Save kayheunen/6334194 to your computer and use it in GitHub Desktop.
AppleScript to Restart WiFi connection, in order to connect to closest AP in your network.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on run | |
try | |
set airport_status to do shell script "networksetup -getairportpower en1" | |
on error | |
display dialog "The script did't work, please check the 'networksetup' command (in terminal) works on your system. " buttons {"kthxbai"} | |
end try | |
if airport_status is "Wi-Fi Power (en1): On" then | |
do shell script "networksetup -setairportpower en1 off" | |
do shell script "networksetup -setairportpower en1 on" | |
else if airport_status is "Wi-Fi Power (en1): Off" then | |
do shell script "networksetup -setairportpower en1 on" | |
else | |
display dialog "The script did't work, please check the Wi-Fi interface name (e.g. en1) " buttons {"kthxbai"} | |
end if | |
end run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In order to get it working you may need to edit the interface name. To get the interface name, you can run the following command in the Terminal:
networksetup -listnetworkserviceorder
You will receive a list that looks something like this:
In my case, the interface name for the Wi-Fi is
en0
(the name next to “Device:”).