Advertisement
Guest User

disabilitaairport

a guest
Jun 19th, 2011
737
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. function set_airport {
  4.  
  5. new_status=$1
  6.  
  7. if [ $new_status = "On" ]; then
  8. /usr/sbin/networksetup -setairportpower en1 on
  9. touch /var/tmp/prev_air_on
  10. else
  11. /usr/sbin/networksetup -setairportpower en1 off
  12. if [ -f "/var/tmp/prev_air_on" ]; then
  13. rm /var/tmp/prev_air_on
  14. fi
  15. fi
  16.  
  17. }
  18.  
  19. function growl {
  20.  
  21. # Checks whether Growl is installed
  22. if [ -f "/usr/local/bin/growlnotify" ]; then
  23. /usr/local/bin/growlnotify -m "$1" -a "AirPort Utility.app"
  24. fi
  25.  
  26. }
  27.  
  28. # Set default values
  29. prev_eth_status="Off"
  30. prev_air_status="Off"
  31.  
  32. eth_status="Off"
  33.  
  34. # Determine previous ethernet status
  35. # If file prev_eth_on exists, ethernet was active last time we checked
  36. if [ -f "/var/tmp/prev_eth_on" ]; then
  37. prev_eth_status="On"
  38. fi
  39.  
  40. # Determine same for AirPort status
  41. # File is prev_air_on
  42. if [ -f "/var/tmp/prev_air_on" ]; then
  43. prev_air_status="On"
  44. fi
  45.  
  46. # Check actual current ethernet status
  47. if [ "`ifconfig en0 | grep \"status: active\"`" != "" ]; then
  48. eth_status="On"
  49. fi
  50.  
  51. # And actual current AirPort status
  52. air_status=`/usr/sbin/networksetup -getairportpower en1 | awk '{ print $4 }'`
  53.  
  54. # If any change has occured. Run external script (if it exists)
  55. if [ "$prev_air_status" != "$air_status" ] || [ "$prev_eth_status" != "$eth_status" ]; then
  56. if [ -f "./statusChanged.sh" ]; then
  57. "./statusChanged.sh" "$eth_status" "$air_status" &
  58. fi
  59. fi
  60.  
  61. # Determine whether ethernet status changed
  62. if [ "$prev_eth_status" != "$eth_status" ]; then
  63.  
  64. if [ "$eth_status" = "On" ]; then
  65. set_airport "Off"
  66. growl "Wired network detected. Turning AirPort off."
  67. else
  68. set_airport "On"
  69. growl "No wired network detected. Turning AirPort on."
  70. fi
  71.  
  72. # If ethernet did not change
  73. else
  74.  
  75. # Check whether AirPort status changed
  76. # If so it was done manually by user
  77. if [ "$prev_air_status" != "$air_status" ]; then
  78. set_airport $air_status
  79.  
  80. if [ "$air_status" = "On" ]; then
  81. growl "AirPort manually turned on."
  82. else
  83. growl "AirPort manually turned off."
  84. fi
  85.  
  86. fi
  87.  
  88. fi
  89.  
  90. # Update ethernet status
  91. if [ "$eth_status" == "On" ]; then
  92. touch /var/tmp/prev_eth_on
  93. else
  94. if [ -f "/var/tmp/prev_eth_on" ]; then
  95. rm /var/tmp/prev_eth_on
  96. fi
  97. fi
  98.  
  99. exit 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement