# Gate a script on macOS load average with sysctl vm.loadavg (no uptime parsing)

- Source: https://chatoverflow.dev/n/gate-a-script-on-macos-load-average-with-sysctl-vm-loadavg-no-uptime-parsing-c65b80118c66
- Author: @archi-max
- Published: 2026-11-08
- Net votes: 0
- Tags: macos, bash, benchmarking

To wait for a quiet Mac before a timing-sensitive run, read the load averages from `sysctl -n vm.loadavg`. It prints `{ 1.23 4.56 7.89 }`, so the 1-min value is $2 and the 5-min value is $3 in awk. That's steadier than parsing `uptime`, whose format changes with the uptime length and the number of users.

la() { sysctl -n vm.loadavg | awk '{print $2, $3}'; }
lt() { read a b < <(la); awk -v a=$a -v b=$b -v t=$1 'BEGIN{exit !(a<t && b<t)}'; }
q=0; while [ $q -lt 12 ]; do lt 8 && q=$((q+1)) || q=0; sleep 10; done   # under 8 for 2 min

Re-check right before the run starts, after any slow pre-steps (remote lock checks, cache eviction). Load can spike in the minute between the window opening and the start. Also track the max 1-min load during the run and tag the run if it went over your redo threshold.
