Want more features on Pastebin? Sign Up, it's FREE!
Guest

wlanmon-xfce-iconic.sh

By: a guest on Jan 7th, 2012  |  syntax: Bash  |  size: 1.51 KB  |  views: 91  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/bin/bash
  2.  
  3. # Stupid wlan quality -> icon converter for Xfce4 panel
  4. # Copyright (C) 2012 Mithat Konar
  5. #
  6. # License: GPL3
  7. #
  8. # Use this script with a Xfce4 genmon panel item.
  9. # Requires gnome-colors-common
  10.  
  11. ###
  12. ### Settings
  13. ###
  14. # name of interface to monitor
  15. WLAN=wlan0
  16.  
  17. # maximum quality level (I used wavemon to figure this out.)
  18. QUAL_MAX=70
  19.  
  20. # app to run when icon is clicked (I'm using wavemon; consider ceni | wpa_gui.)
  21. THE_APP="xterm -e wavemon -i $WLAN"
  22. #~ THE_APP="/<path to>/toggle-xterm wavemon -i $WLAN"
  23.  
  24. # icons
  25. ICON_PATH=/usr/share/icons/gnome-colors-common/22x22/status
  26. ICON_MAX=nm-signal-100.png
  27. ICON_MID=nm-signal-75.png
  28. ICON_LOW=nm-signal-50.png
  29. ICON_MIN=nm-signal-25.png
  30. ICON_UNKNOWN=nm-signal-0.png
  31.  
  32. # lower bounds for link quality levels
  33. MAX=75
  34. MID=50
  35. LOW=25
  36.  
  37. ###
  38. ### MAIN
  39. ###
  40. # snag wlan info
  41. link_data=($(grep $WLAN /proc/net/wireless))
  42. link_quality=`echo ${link_data[2]} | tr -d .`
  43. link_level=`echo ${link_data[3]} | tr -d .`
  44.  
  45. # convert link_quality to percent
  46. link_quality=$((($link_quality*100)/$QUAL_MAX))
  47.  
  48. # pick an icon
  49. if [[ $link_quality -gt $MAX ]] ; then
  50.     the_icon=${ICON_MAX}
  51. elif [[ $link_quality -gt $MID ]] ; then
  52.     the_icon=${ICON_MID}
  53. elif [[ $link_quality -gt $LOW ]] ; then
  54.     the_icon=${ICON_LOW}
  55. elif [[ $link_quality -gt 0 ]] ; then
  56.     the_icon=${ICON_MIN}
  57. else
  58.     the_icon=${ICON_UNKNOWN}
  59. fi
  60.  
  61. # output
  62. echo "<tool>$WLAN: ${link_quality}%, ${link_level}dBm</tool>"
  63. echo "<img>$ICON_PATH/$the_icon</img>"
  64. echo "<click>$THE_APP</click>"
clone this paste RAW Paste Data