Is there a way to list only desktops that contain windows similar to how bspc query -D --names lists all desktops ?
Take a look at the -d option to bspc query, and the list of desktop selectors, which has what you want to do.
bspc query -D -d .occupied --names, found it, thanks
Most helpful comment
bspc query -D -d .occupied --names, found it, thanks