Count the number of open windows
I guess this AppleScript should do:

set numberOfWindows to "0"

tell application "System Events"
    set allProcesses to application processes
    repeat with i from 1 to number of allProcesses
        tell process i
            set numberOfWindows to (numberOfWindows + (count windows))
        end tell
    end repeat
end tell