When integrated with Waybar, this script returns the total number of Windows on all workspaces.

As an example, the returned text below shows that there are 3 windows on 5 workspaces.
{“text”:“3 on 5 “,“tooltip”:“Window Count”,“class”:“unmuted”}

#!/bin/bash

WS="$(niri msg -j workspaces | jq "[.[] | select(.is_urgent == false|true )] | length")"
NUM="$(niri msg -j windows | jq "[.[] | select(.is_focused == false|true )] | length")"

if [[ $NUM -gt 0 ]] then
  TEXT=$NUM" on "$WS
else
  TEXT=$WS
fi

echo '{"text":"'$TEXT' ","tooltip":"Updates available","class":"unmuted"}'