You are not logged in.

#1 2015-06-12 15:58:07

helix
Member
Registered: 2013-02-17
Posts: 180

[SOLVED] Number of open windows per application

I'm trying to write a script that will count how many open windows a specific application has, for example palemoon. I already tried

ps -aux | grep palemoon

While I have two fresh palemoon windows (only one tab per window), the above command shows only one instance of /usr/bin/palemoon running:

ps -aux | grep palemoon
george   31403 13.6 12.6 573188 260000 ?       Sl   18:27   2:56 /usr/bin/palemoon
george   32335  0.0  0.1   4900  2188 pts/3    S+   18:49   0:00 grep palemoon                    <--- this line is ignored

How can I get as a result the real number of open windows for palemoon (which in the above example is obviously 2)?

Last edited by helix (2015-06-12 17:02:38)

Offline

#2 2015-06-12 16:16:23

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,793

Re: [SOLVED] Number of open windows per application

xwininfo -root -tree  should provide more than enough information tongue


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2015-06-12 17:00:39

helix
Member
Registered: 2013-02-17
Posts: 180

Re: [SOLVED] Number of open windows per application

Thank you ewaller, exactly what I wanted! This did the trick:

xwininfo -root -tree | grep moon | grep '^         ' | wc -l

For some reason the program name in the results of xwininfo is "Pale Moon" or "Pale moon", so grepping palemoon instead of moon would fail

Offline

#4 2015-06-12 17:04:32

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: [SOLVED] Number of open windows per application

It sure does provide a lot of info, but parsing it seems tricky.
I don't even know how to count how many tabs one instance of firefox has open.


@OP
Why do you need this information?

Edit: Does

xwininfo -root -tree | grep -ci moon

work too?

Last edited by karol (2015-06-12 17:06:23)

Offline

#5 2015-06-12 18:02:54

helix
Member
Registered: 2013-02-17
Posts: 180

Re: [SOLVED] Number of open windows per application

No, it gives result 16

Offline

Board footer

Powered by FluxBB