Advertisement
MarkehMe

Don't like your AirPort being disconnected on Mac?

Sep 13th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # By Mark Hughes (www.markeh.me)
  3. #
  4. # See http://markeh.me/blog/dont-like-your-airport-being-disconnected-on-mac-i-have-the-solution/89
  5. #
  6.  
  7. # First we want to see if we're connected to a network
  8. NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
  9.  
  10. if [ "$NETWORK_TEST" = "" ]; then
  11.     echo "AirPort is connected.";
  12.     #echo "$NETWORK_TEST"; # Debugging purposes!
  13.  
  14. else
  15.     echo "AirPort is not connected to a network, wait 10 seconds and try again.";
  16.     sleep 10;
  17.    
  18.     # Re-run the test
  19.     NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
  20.  
  21.     if [ "$NETWORK_TEST" = "" ]; then
  22.         echo "AirPort is now connected.";
  23.     else
  24.         echo "AirPort is not connected to a network, restarting the airport power.";
  25.        
  26.         networksetup -setairportpower en1 off
  27.         # Just wait for everything to calm down, 1 second could probably do it even.
  28.         sleep 2
  29.         networksetup -setairportpower en1 on
  30.        
  31.         echo "Waiting 5 seconds for the AirPort to find something.";
  32.         sleep 5
  33.        
  34.         NETWORK_TEST=`networksetup -getairportnetwork en1 | grep "not associated"`;
  35.        
  36.         if [ "$NETWORK_TEST" = "" ]; then
  37.             echo "AirPort has now found a network.";
  38.             # Take further action? Log something? Do something? Anything?
  39.         else
  40.             echo "No network could be found.";
  41.         fi
  42.     fi
  43. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement