Way to get network traffic on the Touchbar?

I know about iStat menus, etc, but I want my network traffic on the touchbar. Anyone know how I can make that happen? I suspect an Applescript or CLI setup will be able to make it happen, but I have no idea how to do that.

Any ideas?

Thanks in advance!

I am doing this via a python script to get network traffic and an apple script inside BTT to fill the button.

Python Code (saved as getNetStats.py):

import time
import psutil

def main():
    old_value = 0
    old_value_send = 0

    while True:
        new_value = psutil.net_io_counters().bytes_recv
        new_value_send = psutil.net_io_counters().bytes_sent
        if old_value:
            send_stat(new_value - old_value, new_value_send - old_value_send)

        old_value = new_value
        old_value_send = new_value_send


def convert_to_mbit(value):
    return value/1024./1024.*8

def send_stat(value_recv, value_send):
    print "{0:.2f}\t{1:.2f}".format(convert_to_mbit(value_recv), convert_to_mbit(value_send))


Script for BTT Widget:

set value to do shell script "/usr/bin/python /LOCATION_TO/getNetStat.py"

set myArray to my theSplit(value, "	")

on theSplit(theString, theDelimiter)
	-- save delimiters to restore old settings
	set oldDelimiters to AppleScript's text item delimiters
	-- set delimiters to delimiter to be used
	set AppleScript's text item delimiters to theDelimiter
	-- create the array
	set theArray to every text item of theString
	-- restore the old setting
	set AppleScript's text item delimiters to oldDelimiters
	-- return the result
	return theArray
end theSplit

set value1 to item 1 of myArray & "▼
" & item 2 of myArray & "▲"

return value1

With a little customization, the button looks like:


Speeds are in Mbps

1 Like

I like the way this looks. Where would I learn how to add this to my BTT?

Imprint | Privacy Policy