Skip to main content

I wrote this macOS bash Worklet with the help of Otto AI to check the speed of an internet connection on macOS devices.

It’s my entry into the Just Script It challenge! 

Evaluation


# This Worklet runs a speed test on Mac OS devices using the networkQuality command.
# This command was included starting with Mac OS Monterrey.
#Exit non-compliant to run remediation script
exit 1

 

Remediation

# ======================
# Otto AI Generated Code
# ======================

#intro message:
clear
echo "Checking Network Quality......"

# s allows for sequential testing, which tends to yield more accurate results
# c is computer readable output
# networkQuality available starting with Monterrey

output=$(networkQuality -sc)

# Remove leading/trailing whitespace and curly braces
output=${output#*{}
output=${output%{}*}

# Extract the values using pattern matching
uplink_capacity=$(grep -o '"ul_throughput" : t0-9]*' <<< "$output" | awk '{print $NF}')
uplink_capacity=$(($uplink_capacity/1000000))
downlink_capacity=$(grep -o '"dl_throughput" : t0-9]*' <<< "$output" | awk '{print $NF}')
downlink_capacity=$(($downlink_capacity/1000000))
os_version=$(grep -o '"os_version" : ""^"]*"' <<< "$output" | cut -d'"' -f4)
interface=$(grep -o '"interface_name" : ""^"]*"' <<< "$output" | cut -d'"' -f4)

#Get info on whether connection is WiFi or Ethernet
network_type=$(networksetup -listnetworkserviceorder | grep -C1 $interface)
connection_type=$(echo "$network_type" | awk -F 'Hardware Port: ' '/Hardware Port:/{print $2}' | cut -d',' -f1)

clear

#Output the Info
echo "Download Speed: $downlink_capacity Mbps"
echo "Upload Speed: $uplink_capacity Mbps"
echo "OS Version: $os_version"
echo "Interface: $interface"
echo "Connection Type: $connection_type"

 

Awesome work on this, Landon! Thanks for sharing :) 


Reply