10

An updated script by Thieri where you can modify easily the way it is displayed along with different colour schemes.

This will display your bluetooth Trackpad, Keyboard, and Mouse battery levels depending on which devices you want to see on your screen. An example would be to display the Trackpad and Keyboard as you don't use a mouse. It can be stacked vertically or horizontally easily by changing the values in the script.

Here is the script

##################################################################################################################################################
@ Original concept by: Thieri (2011)                                                         #
# This script displays Trackpad, Keyboard, and Mouse battery.                                            #
# You can display individually or a combination by changing the global setting below.                                #
# You can have it display either horizontally or vertically by changing the global setting below.                        #
# You can change the meter character as well as the separator (horizontally) for each device separately below.                   #
# You can change the colour for each of the devices display separately below.  See the colour chart below                    #
# The font and frame positioning are set either by the properties section or by entering the positions in the frame settings within this script. #
# The refresh interval is set at 300 which is 5 minutes.  That can be changed in the area where the frame settings are.              #
#                                                                        #
# Here’s some position settings with a resolution of 1080p centred at the top of the screen:                             #
# Horizontal Setting:                                                                #
# {{466, 26}, {1033, 45}}   Trackpad / Keyboard / Mouse                                          #
# {{614, 26}, {700, 45}}    Trackpad / Keyboard                                              #
# {{749, 26}, {333, 45}}    Trackpad                                                     #
#                                                                        #
# Vertical Setting:                                                              #
# {{770, 27}, {355, 75}}    Trackpad / Keyboard / Mouse                                          #
# {{771, 27}, {355, 50}}    Trackpad / Keyboard                                              #
# {{771, 27}, {355, 45}}    Trackpad                                                     #
#                                                                        #
# Colour chart                                                                   #
# "\033[0m"                 # Reset                                              #
# "\033[30m"                    # Black                                              #
# "\033[31m"                    # Red                                                #
# "\033[32m"                    # Green                                              #
# "\033[33m"                    # Yellow                                             #
# "\033[34m"                    # Blue                                               #
# "\033[35m"                    # Magenta                                            #
# "\033[36m"                    # Cyan                                               #
# "\033[37m"                    # White                                              #
# "\033[1m\033[30m"                 # Bold Black                                             #
# "\033[1m\033[31m"                 # Bold Red                                           #
# "\033[1m\033[32m"                 # Bold Green                                             #
# "\033[1m\033[33m"                 # Bold Yellow                                            #
# "\033[1m\033[34m"                 # Bold Blue                                          #
# "\033[1m\033[35m"                 # Bold Magenta                                           #
# "\033[1m\033[36m"                 # Bold Cyan                                          #
# "\033[1m\033[37m"                 # Bold White                                             #
##################################################################################################################################################

# Set variables

TrackPadDisplay=1               # 1=on / 0=off
KeyboardDisplay=1               # 1=on / 0=off
MouseDisplay=1                  # 1=on / 0=off
DisplayDir=1                    # 1=horz / 0=vert
NewLine="\n"                    # new line characters

# Trackpad colors 
TrackPadLabelColor="\033[37m"           # white
TrackPadDisconnectColor="\033[31m"      # red
TrackPadPercentLessColor1="\033[31m"        # red
TrackPadPercentLessColor2="\033[36m"        # cyan
TrackPadGridColor1="\033[0;33m"         # yellow
TrackPadGridColor2="\033[0m"            # reset
TrackPadPercentColor="\033[37m"         # white
TrackPadSeperatorColor="\033[35m"       # magenta
TrackPadMeterLine="|"               # can be any character, usually the forward slash "/".  Empty quotes display no separator
TrackPadSeperator="/"               # can be any character, usually the pipe symbol "|"

# Keyboard colors 
KeyboardLabelColor="\033[37m"           # white
KeyboardDisconnectColor="\033[31m"      # red
KeyboardPercentLessColor1="\033[31m"        # red
KeyboardPercentLessColor2="\033[36m"        # cyan
KeyboardGridColor1="\033[0;33m"         # yellow
KeyboardGridColor2="\033[0m"            # reset
KeyboardPercentColor="\033[37m"         # white
KeyboardSeperatorColor="\033[35m"       # magenta
KeyboardMeterLine="|"               # can be any character, usually the forward slash "/".  Empty quotes display no separator
KeyboardSeperator="/"               # can be any character, usually the pipe symbol "|"

# Mouse colors 
MouseLabelColor="\033[37m"          # white
MouseDisconnectColor="\033[31m"         # red
MousePercentLessColor1="\033[31m"       # red
MousePercentLessColor2="\033[36m"       # cyan
MouseGridColor1="\033[0;33m"            # yellow
MouseGridColor2="\033[0m"           # reset
MousePercentColor="\033[37m"            # white
MouseSeperatorColor="\033[35m"          # magenta
MouseMeterLine="|"              # can be any character, usually the forward slash "/".  Empty quotes display no separator
MouseSeperator=" "              # can be any character, usually the pipe symbol "|"

# Main Program

# Trackpad

if [ ${TrackPadDisplay} = 1 ]
then
    if [ ${DisplayDir} = 0 ]
    then    
        echo $TrackPadLabelColor"Trackpad:\t\c"
    else
        echo $TrackPadLabelColor"Trackpad:   \c"
    fi      

    TrackpadPercent=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`

    typeset -i b=5

    if [ ${#TrackpadPercent} = 0 ]
    then
        echo $TrackPadDisconnectColor "Disconnected \t\t"$TrackPadSeperatorColor $TrackPadSeperator "\t\t \c"
    else

        if [ $TrackpadPercent -lt 11 ]
        then
            echo $TrackPadPercentLessColor1"\c"
        else
            echo $TrackPadPercentLessColor2"\c"
        fi

        typeset -i b=5
        while [ $b -le $TrackpadPercent ]
        do
            echo $TrackPadMeterLine"\c"
            b=`expr $b + 5`
        done


        while [ $b -le 100 ]
        do
            echo $TrackPadGridColor1$TrackPadMeterLine$TrackPadGridColor2"\c"
            b=`expr $b + 5`
        done

        echo $TrackPadPercentColor $TrackpadPercent% $TrackPadSeperatorColor $TrackPadSeperator " \c"

        unset TrackpadPercent
        unset b
    fi
fi

# Keyboard

if [ ${KeyboardDisplay} = 1 ]
then
    typeset -i b=5
    if [ ${DisplayDir} = 0 ]
    then    
        echo $NewLine$KeyboardLabelColor"Keyboard:\t\c"
    else
        echo $KeyboardLabelColor"Keyboard:   \c"
    fi      

    KeyboardPercent=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`

    if [ ${#KeyboardPercent} = 0 ]
    then
        echo $KeyboardDisconnectColor" Disconnected \t\t"$KeyboardSeperatorColor $KeyboardSeperator "\t\t \c"
    else

        if [ $KeyboardPercent -lt 11 ]
        then
            echo $KeyboardPercentLessColor1"\c"
        else
            echo $KeyboardPercentLessColor2"\c"
        fi

        while [ $b -le $KeyboardPercent ]
        do
            echo $KeyboardMeterLine"\c"
            b=`expr $b + 5`
        done

        while [ $b -le 100 ]
        do
            echo $KeyboardGridColor1$KeyboardMeterLine$KeyboardGridColor2"\c"
            b=`expr $b + 5`
        done

        echo $KeyboardPercentColor $KeyboardPercent% $KeyboardSeperatorColor $KeyboardSeperator " \c"

        unset KeyboardPercent
        unset b
    fi
fi

# Mouse

if [ ${MouseDisplay} = 1 ]
then
    typeset -i b=5
    if [ ${DisplayDir} = 0 ]
    then    
        echo $NewLine$MouseLabelColor"Mouse:\t\t\c"
    else
        echo $MouseLabelColor"Mouse:   \c"
    fi      

    MousePercent=`ioreg -c BNBMouseDevice | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,",=]//g' | tail -1 | awk '{print $1}'`

    if [ ${#MousePercent} = 0 ]
    then
        echo $MouseDisconnectColor" Disconnected \t\t"$MouseSeperatorColor $MouseSeperator "\t\t \c"
    else

    if [ $MousePercent -lt 11 ]
    then
        echo $MousePercentLessColor1"\c"
    else
        echo $MousePercentLessColor2"\c"
    fi

    typeset -i b=5
    while [ $b -le $MousePercent ]
    do
        echo $MouseMeterLine"\c"
        b=`expr $b + 5`
    done


    while [ $b -le 100 ]
    do
        echo $MouseGridColor1$MouseMeterLine$MouseGridColor2"\c"
        b=`expr $b + 5`
    done

        echo $MousePercentColor $MousePercent% $MouseSeperatorColor $MouseSeperator " \c"

        unset MousePercent
        unset b
    fi
fi

# Unset variables
unset TrackPadLabelColor
unset TrackPadDisconnectColor
unset TrackPadPercentLessColor1
unset TrackPadPercentLessColor2
unset TrackPadGridColor1
unset TrackPadGridColor2
unset TrackPadPercentColor
unset TrackPadSeperatorColor
unset TrackPadMeterLine
unset TrackPadSeperator

unset KeyboardLabelColor
unset KeyboardDisconnectColor
unset KeyboardPercentLessColor1
unset KeyboardPercentLessColor2
unset KeyboardGridColor1
unset KeyboardGridColor2
unset KeyboardPercentColor
unset KeyboardSeperatorColor
unset KeyboardMeterLine
unset KeyboardSeperator

unset MouseLabelColor
unset MouseDisconnectColor
unset MousePercentLessColor1
unset MousePercentLessColor2
unset MouseGridColor1
unset MouseGridColor2
unset MousePercentColor
unset MouseSeperatorColor
unset MouseSeperator
unset MouseMeterLine

unset TrackPadDisplay
unset KeyboardDisplay
unset MouseDisplay
unset DisplayDir
unset NewLine

Comments

User Avatar
BigBadBobD 1697 days ago
pretty cool.. anyway to change the name of the mouse or trackpad?

Log in to comment or register here.