From b42563d10ecab2a7b8b6d6e8967c07cdc6ccd4f4 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 11 Sep 2013 21:15:43 +0100 Subject: Add examples directory --- README.md | 2 +- example.sh | 33 --------------------------------- examples/test.sh | 33 +++++++++++++++++++++++++++++++++ examples/wifi-signal | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 34 deletions(-) delete mode 100755 example.sh create mode 100755 examples/test.sh create mode 100755 examples/wifi-signal diff --git a/README.md b/README.md index 1c01c0b..dc9bba8 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ instantly make tray icons out of them (3G signal strength for example). ## Example run -This example is also in `example.sh` so you can try running it. +This example is also in `examples/test.sh` so you can try running it. ```bash #!/bin/bash diff --git a/example.sh b/example.sh deleted file mode 100755 index 9660ddd..0000000 --- a/example.sh +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/bash - -# Set up tray icon -mkfifo /tmp/$$.icon -./mktrayicon /tmp/$$.icon & - -# Manipulate tray icon - -# Click handling -echo "c xterm -e /bin/sh -c 'iwconfig; read'" > /tmp/$$.icon - -# Change the icon and tooltip -for i in none weak ok good excellent; do - echo "i network-wireless-signal-$i-symbolic" > /tmp/$$.icon - echo "t Signal strength: $i" > /tmp/$$.icon - sleep 1 -done - -# Remove tooltip and click handler -echo "c" > /tmp/$$.icon -echo "t" > /tmp/$$.icon - -# Toggle the visibility of the icon for a bit -for i in {1..3}; do - for j in h s; do - echo $j > /tmp/$$.icon - sleep .5s - done -done - -# Remove tray icon -echo "q" > /tmp/$$.icon -rm /tmp/$$.icon diff --git a/examples/test.sh b/examples/test.sh new file mode 100755 index 0000000..9660ddd --- /dev/null +++ b/examples/test.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +# Set up tray icon +mkfifo /tmp/$$.icon +./mktrayicon /tmp/$$.icon & + +# Manipulate tray icon + +# Click handling +echo "c xterm -e /bin/sh -c 'iwconfig; read'" > /tmp/$$.icon + +# Change the icon and tooltip +for i in none weak ok good excellent; do + echo "i network-wireless-signal-$i-symbolic" > /tmp/$$.icon + echo "t Signal strength: $i" > /tmp/$$.icon + sleep 1 +done + +# Remove tooltip and click handler +echo "c" > /tmp/$$.icon +echo "t" > /tmp/$$.icon + +# Toggle the visibility of the icon for a bit +for i in {1..3}; do + for j in h s; do + echo $j > /tmp/$$.icon + sleep .5s + done +done + +# Remove tray icon +echo "q" > /tmp/$$.icon +rm /tmp/$$.icon diff --git a/examples/wifi-signal b/examples/wifi-signal new file mode 100755 index 0000000..766bb10 --- /dev/null +++ b/examples/wifi-signal @@ -0,0 +1,41 @@ +#!/bin/bash +wifi="/tmp/$$-wifi.icon" + +# Set up tray icon +mkfifo $wifi +mktrayicon $wifi 2>/dev/null & +echo "h" > $wifi +run=1 + +trap 'run=0' INT; +while [[ $run -eq 1 ]]; do + # See network-manager:wifi:wext_qual_to_percent + # http://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/src/wifi/wifi-utils-wext.c#n264 + qual=`iwconfig 2>/dev/null | grep "Link Quality" | sed 's/.*Link Quality=\([0-9]*\/[0-9]*\) .*/\1/'` + if [[ -n $qual ]]; then + qual=`echo "100*$qual" | bc` + if ((qual<25)); then + echo "i network-wireless-signal-weak-symbolic" > $wifi; + echo "t Weak ($qual%)" > $wifi; + elif ((qual<50)); then + echo "i network-wireless-signal-ok-symbolic" > $wifi; + echo "t OK ($qual%)" > $wifi; + elif ((qual<75)); then + echo "i network-wireless-signal-good-symbolic" > $wifi; + echo "t Good ($qual%)" > $wifi; + else + echo "i network-wireless-signal-excellent-symbolic" > $wifi; + echo "t Excellent ($qual%)" > $wifi; + fi + + echo "s" > $wifi; + else + echo "h" > $wifi; + fi + + sleep 30 +done + +# Remove tray icon +echo "q" > $wifi +rm $wifi -- cgit