Created
February 10, 2023 21:37
-
-
Save jasonsnell/2be0c902f02c7e9f2e820f7be50e097b to your computer and use it in GitHub Desktop.
NetworkQuality for SwiftBar
This file contains 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
#! /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) |
SwiftBar and xBar use the filename to determinethe frequency. So you'd replace "30m" in the filename with anything you want. It does take a while to run so I wouldn't make it refresh too often or it'll be eternally running.
Thank you very much! I love this plugin!
[Rich]
…On Fri, Feb 17, 2023 at 6:51 PM jasonsnell ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
SwiftBar and xBar use the filename to increase the frequency. So you'd
replace "30m" in the filename with anything you want. It does take a while
to run so I wouldn't make it refresh too often or it'll be eternally
running.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/2be0c902f02c7e9f2e820f7be50e097b#gistcomment-4474912>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJBGUSMLM26AT4ELFH6BSWLWYAFGHBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTEMBYGU2DIMBWU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you commented on the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What line of code would I need to change to increase the frequency of refresh? Thanks!