#!/usr/bin/env bash # Outputs JSON for Waybar showing workspace name + number of windows workspaces=$(hyprctl workspaces -j) json="[" index=0 for ws in $(echo "$workspaces" | jq -r '.[] | @base64'); do _jq() { echo "$ws" | base64 --decode | jq -r "$1"; } ws_id=$(_jq '.id') ws_name=$(_jq '.name') # Count windows in this workspace win_count=$(hyprctl clients -j | jq "[.[] | select(.workspace.id==$ws_id)] | length") # Output JSON json+=$(jq -n \ --arg text "$ws_name ($win_count)" \ --arg tooltip "$(bash ~/.config/waybar/scripts/hypr-workspacesmenu.sh $ws_id)" \ '{text: $text, tooltip: $tooltip}') index=$((index+1)) [ $index -lt $(echo "$workspaces" | jq length) ] && json+="," done json+="]" echo "$json"