Last active
August 29, 2015 14:20
-
-
Save caseymhunt/972272a0b64edf692cc6 to your computer and use it in GitHub Desktop.
A script for the Today-Scripts project which adds a battery status to the sidebar- includes mouse battery status.
This file contains hidden or 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
| full=$(pmset -g batt | { read; read n full; echo "$full"; }) | |
| batt=$(echo "$full" | cut -d';' -f1 | tr -d '%') | |
| status=$(echo "$full" | cut -d';' -f2 | tr -d ' ') | |
| time=$(echo "$full" | cut -d';' -f3 | sed 's/^ *//') | |
| mousebatt=$(ioreg -n "BNBMouseDevice" | grep -i '"batterypercent" =' | sed 's/[^[:digit:]]//g') | |
| noc=$'\e[39m' | |
| if (($batt >= 66)); then battc=$'\e[32m'; | |
| elif (($batt >= 33)); then battc=$'\e[33m'; | |
| else battc=$'\e[31m'; | |
| fi; | |
| if [ $mousebatt ] | |
| then | |
| if (($mousebatt >= 66)); then mousebattc=$'\e[32m'; | |
| elif (($mousebatt >= 33)); then mousebattc=$'\e[33m'; | |
| else mousebattc=$'\e[31m'; | |
| fi; | |
| fi; | |
| if [ "$status" == "discharging" ]; then | |
| statc=$'\e[31m'; | |
| elif [ "$status" == "charging" ]; then | |
| statc=$'\e[32m'; | |
| elif [ "$status" == "charged" ]; then | |
| statc=$'\e[32m'; | |
| else | |
| statc=$'\e[33m'; | |
| fi | |
| echo -e "---Computer Battery---" | |
| echo "$battc$batt%$noc | $statc$status$noc | $time" | |
| echo -e "\n---Bluetooth Mouse---" | |
| if [ $mousebatt ]; | |
| then echo "$mousebattc$mousebatt%$noc"; | |
| else echo "No Mouse Detected"; | |
| fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment