Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a tool to count the number of windows I have open, including on all Spaces?

I am curious and too lazy to do it manually. :)

share|improve this question

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
share|improve this answer
Lol: tell app "System Events" to count windows of processes – user495470 Mar 3 '11 at 6:27
@l-ri I made my statement deliberately more verbose, given that other users usually want to incorporate more than just a count of all processes´ windows and thus might learn more this way - but true, your version is shorter. Don´t get how your Lol is supposed to be helpful, though. – Asmus Mar 3 '11 at 10:14
OK, so I paste that into the AppleScript editor and I get: 'error "System Events got an error: Access for assistive devices is disabled."' How do I enable it? For applications that I've installed previously that needed this, the app itself prompts me. "Enable access for assistive devices" is enabled in my system preferences. – Reid Mar 3 '11 at 19:15
You can check whether it´s enabled by running tell application "System Events" to get UI elements enabled. You can enable it by adding tell application "System Events" to set UI elements enabled to true in the beginning of the script; though it seems strange for me, that it seems to be already enabled in your case. – Asmus Mar 3 '11 at 20:20
OK, so tell application "System Events" to get UI elements enabled returns true, but the error above still happens, even with adding the enabler line you suggest to the beginning. – Reid Mar 7 '11 at 21:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.