Skip to main content
Question

The networkQuality Is Not Strained

  • December 16, 2021
  • 10 replies
  • 57 views

brockwalters
Forum|alt.badge.img+8

I posted this in the macadmin Slack & kind of forgot to post it here...

Just a 1st crack at it, but, I put this in Self Service so users can run the networkQuality tests. 

  • It gives the user the choice to run the parallel or serial test
  • It shows a progress screen
  • It displays the results at the end of the test in a dialog

You may need to set AppleScript PPPC exceptions but these osascript commands for the most part on recent versions of macOS should be fine without them. Enjoy!

P.S. macOS Monterey only as far as I know... Sorry.

 

#!/bin/zsh filpth='/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources' tsttyp=$(/usr/bin/osascript -e "choose from list {\\"Download + Upload Speed\\", \\"Video Conferencing\\"} with title \\"Network Quality Test\\" with prompt \\"Please select test type to begin:\\"") case "$tsttyp" in 'false' ) exit ;; 'Download + Upload Speed' ) icnsnm='GenericNetworkIcon' option='-sv' ;; 'Video Conferencing' ) icnsnm='GroupIcon' option='-v' ;; esac /usr/bin/osascript -e "display dialog \\"Test in progress...\\n\\" buttons {\\"Cancel\\"} with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" & prgpid=$! /usr/bin/networkquality "$option" | /usr/bin/sed '/SUMMARY/d' > /private/tmp/summary.txt & while true do if [ -n "$(/bin/cat /private/tmp/summary.txt)" ] then break fi if /bin/kill -s 0 "$prgpid" then >&2 echo "waiting for networkquality..." /bin/sleep 3 else exit fi done >&2 echo "$(/bin/cat /private/tmp/summary.txt)" /usr/bin/osascript -e "display dialog \\"$(/bin/cat /private/tmp/summary.txt)\\" buttons {\\"Ok\\"} default button 1 with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" /bin/rm -rf /private/tmp/summary.txt /bin/kill -9 "$prgpid"

 

 

10 replies

AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • December 17, 2021

This looks very cool! I tried running it in Terminal and got the Test in Progress window, but Terminal just said 

no such file or directory: /usr/bin/networkquality

Sure enough, that file does not exist. Where can one obtain said file? 


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • December 17, 2021

This looks very cool! I tried running it in Terminal and got the Test in Progress window, but Terminal just said 

no such file or directory: /usr/bin/networkquality

Sure enough, that file does not exist. Where can one obtain said file? 


aaahhhhh.... it's only in Monterey. I ran it on my Monterey Mac and it does look very handy..


brockwalters
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • December 17, 2021

Yes. I kind of failed to mention that. 🙂 Sorry!


wnetto-aix
Forum|alt.badge.img
  • New Contributor
  • June 2, 2022

 This is excellent, thank you!


donmontalvo
Forum|alt.badge.img+36
  • Hall of Fame
  • August 26, 2022

Guessing it no likey proxy servers. #sigh

+1 Kudo, since I know if @brockwalters wrote it, it works. :)


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • October 31, 2023

I tried the script as a policy in Self Service under Sonoma and the output is unreadable. When I run the networkquality command (not in the script) on Sonoma in Terminal, it runs and produces readable output. When I run the script in Self Service on Monterey and Ventura, it also produces readable output.  Any ideas as to what changed in Sonoma?

 


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • October 31, 2023

I’m digging through it and I see that the output of the networkquality -v (verbose) command in Sonoma doesn’t have “summary”. The script’s call for sed to parse that out fails. It needs to look for the line that says “verbose” and parse that. I’ve played around with editing the script accordingly and running it locally, but I can’t seem to make it work.  I know I’m a sed/awk idiot so there’s little chance I’ll be able to fix it on my own. 


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • November 1, 2023

After dancing with ChatGPT for a while to get the grammar of awk correct, I have come up with a script that will work on Monterey, Ventura, and Sonoma.  I know it's not efficient, but it works. Basically I took the core of the script and made 2 functions with it. One function is for Monterey/Ventura and the other function is for Sonoma - the difference is whether it looks for "SUMMARY" or "Verbose". After defining the functions, then it does an OS check and that will determine which function it will run. 

#!/bin/zsh # https://community.jamf.com/t5/jamf-pro/the-networkquality-is-not-strained/td-p/254301 ventura() { option='0' filpth='/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources' tsttyp=$(/usr/bin/osascript -e "choose from list {\\"Download + Upload Speed\\", \\"Video Conferencing\\"} with title \\"Network Quality Test\\" with prompt \\"Please select test type to begin:\\"") case "$tsttyp" in 'false' ) exit ;; 'Download + Upload Speed' ) icnsnm='GenericNetworkIcon' option='1' ;; 'Video Conferencing' ) icnsnm='GroupIcon' option='2';; esac /usr/bin/osascript -e "display dialog \\"Test in progress...\\n\\" buttons {\\"Cancel\\"} with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" & prgpid=$! if [[ $option == 1 ]] ; then /usr/bin/networkquality -sv | /usr/bin/sed '/SUMMARY/d' > /private/tmp/summary.txt & else /usr/bin/networkquality -v | /usr/bin/sed '/SUMMARY/d' > /private/tmp/summary.txt & fi while true do if [ -n "$(/bin/cat /private/tmp/summary.txt)" ] then break fi if /bin/kill -s 0 "$prgpid" then >&2 echo "waiting for networkquality..." /bin/sleep 3 else exit fi done result="$(/bin/cat /private/tmp/summary.txt)" >&2 echo "$result" /usr/bin/osascript -e "display dialog \\"$result\\" buttons {\\"Ok\\"} default button 1 with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" #/bin/rm -rf /private/tmp/summary.txt /bin/kill -9 "$prgpid" } sonoma() { option='0' filpth='/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources' tsttyp=$(/usr/bin/osascript -e "choose from list {\\"Download + Upload Speed\\", \\"Video Conferencing\\"} with title \\"Network Quality Test\\" with prompt \\"Please select test type to begin:\\"") case "$tsttyp" in 'false' ) exit ;; 'Download + Upload Speed' ) icnsnm='GenericNetworkIcon' option='1' ;; 'Video Conferencing' ) icnsnm='GroupIcon' option='2';; esac /usr/bin/osascript -e "display dialog \\"Test in progress...\\n\\" buttons {\\"Cancel\\"} with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" & prgpid=$! if [[ $option == 1 ]] ; then /usr/bin/networkquality -sv | awk '/Verbose/ {flag=1; next} flag;' > /private/tmp/summary.txt & else /usr/bin/networkquality -v | awk '/Verbose/ {flag=1; next} flag;' > /private/tmp/summary.txt & fi while true do if [ -n "$(/bin/cat /private/tmp/summary.txt)" ] then break fi if /bin/kill -s 0 "$prgpid" then >&2 echo "waiting for networkquality..." /bin/sleep 3 else exit fi done result="$(/bin/cat /private/tmp/summary.txt)" >&2 echo "$result" /usr/bin/osascript -e "display dialog \\"$result\\" buttons {\\"Ok\\"} default button 1 with icon POSIX file \\"$filpth/$icnsnm.icns\\" with Title \\"Network Quality Test - $tsttyp\\"" #/bin/rm -rf /private/tmp/summary.txt /bin/kill -9 "$prgpid" } ########## OS check ################ # Fetch the macOS version os_version=$(sw_vers -productVersion) # Extract the major version number major_version=$(echo $os_version | cut -d. -f1) # Check the major version number and echo the corresponding message if [ "$major_version" = "13" ]; then echo "running ventura command" ventura elif [ "$major_version" = "12" ]; then echo "running ventura command" ventura elif [ "$major_version" = "14" ]; then echo "running sonoma command" sonoma else echo "This version is not Ventura or Sonoma." fi #####################################

The output in Sonoma has more details so the window displaying the results can get kinda long, but it should still fit on your screen.

 


AVmcclint
Forum|alt.badge.img+21
  • Esteemed Contributor
  • November 1, 2023

oops... for some reason I can't edit the script here on JamfNation.  You will want to uncomment (remove the #) the two instances of 

#/bin/rm -rf /private/tmp/summary.txt

brockwalters
Forum|alt.badge.img+8
  • Author
  • Valued Contributor
  • November 1, 2023

Thanks for the update! I'll take a look at it in detail.