BitBar: Easy Custom Menu Bar Apps

BitBar is a free app for macOS which — essentially — lets you create custom menu bar apps from shell scripts or other command line tools. If you can write a program or script (in Shell, Python, C, Swift) and print, you can put something in the menu bar. BitBar also lets you define how often it should automatically refresh each specific script.

My favorite thing I’ve made uses the speedtest-cli tool to refresh what my current download and upload speeds are and show colorized output based on the results.

2020 20 03 bitbar speedtest

The script might look strange if you’re not used to awk, but the main thing to know is that $2 (the second space separated for the line) represents the result number and $0 represents the whole line. So I’m grabbing the number and then printing the whole line with a color based on the value. Also, awk is cool and you should learn it.

#!/usr/bin/env zsh

echo "⏱"
echo "---"

/opt/local/bin/speedtest-cli |
awk '/Download/ {
        if ($2 < 25) {
            print $0, "|", "color=red"
        } else if ($2 < 90) {
            print $0, "|", "color=orange"
        } else {
            print $0, "|", "color=green"
        }
    }
    /Upload/ {
        if ($2 < 4) {
            print $0, "|", "color=red"
        } else if ($2 < 9) {
            print $0, "|", "color=orange"
        } else {
            print $0, "|", "color=green"
        }
    }'
Collin Donnell @collin