Skip to content

Instantly share code, notes, and snippets.

@jasonsnell
Created February 10, 2023 21:37
Show Gist options
  • Save jasonsnell/2be0c902f02c7e9f2e820f7be50e097b to your computer and use it in GitHub Desktop.
Save jasonsnell/2be0c902f02c7e9f2e820f7be50e097b to your computer and use it in GitHub Desktop.
NetworkQuality for SwiftBar
#! /usr/bin/python3
# <xbar.title>Network Quality</xbar.title>
# <xbar.version>v1.1</xbar.version>
# <xbar.author>Jason Snell</xbar.author>
# <xbar.author.github>jasonsnell</xbar.author.github>
# <xbar.desc>Display current network quality from networkQuality binary.</xbar.desc>
# <swiftbar.hideRunInTerminal>true</swiftbar.hideRunInTerminal>
import json
import subprocess
newline = "\n"
def mbps(speed):
return int(round((speed / 1024 / 1024), 0))
# Args: c – outputs in JSON, s – tests download and upload separately
cmd = ["/usr/bin/networkQuality", "-c", "-I", "en0"]
response = json.loads(subprocess.run(cmd, capture_output=True, text=True).stdout)
dl_throughput = mbps(response.get("dl_throughput", 0))
ul_throughput = mbps(response.get("ul_throughput", 0))
responsiveness = response.get("responsiveness")
theOutput = (
f"{ul_throughput} :icloud.and.arrow.up: {dl_throughput} "
f":icloud.and.arrow.down:{newline}---{newline}{responsiveness}"
)
print(theOutput)
@rytch0
Copy link

rytch0 commented Feb 17, 2023

What line of code would I need to change to increase the frequency of refresh? Thanks!

@jasonsnell
Copy link
Author

jasonsnell commented Feb 17, 2023 via email

@rytch0
Copy link

rytch0 commented Feb 17, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment