Re: need "windowlist" info externally, not interactively

Axel Beckert <[email protected]>
Newsgroups gmane.comp.gnu.screen.user
Organization DeuxChevaux.org -- The Citr oën 2CV Database
Message-ID <[email protected]>
Hi,

On Sun, Oct 18, 2015 at 11:13:07PM +0000, Anonymous wrote:
> A shell script needs to be able to add a window, and know in advance
> what window number is still available.  It will then do some stuffing.
> 
> ATM it's quite messy and complex.  The script attempts to randomly
> create a title then use that as a handle, but then it must eventually
> rename the window to something sensible.  Sometimes it screws up and
> clobbers an existing window.

Which screen commandline parameters do you use for that? I'd expect
something like "screen -X screen 63 somecommand". (Would run
"somecommand" in a window with number 63 unless that number is already
in use.)

> I need a more sensible option.  E.g. I need to be able to do something
> like "screen -x user/session -windowlist", and simply get a dump of
> windows, which the script can then parse.

Have you tried "screen -Q windows"? Unfortunately it seems to be
truncated to the width of the screen session's bottom line. Luckily it
seems truncated at the beginning, i.e. you always see the highest number:

Get the highest window number:

$ screen -Q windows | sed -e 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/'
10
$

Run "mc" in a window with one window number higher than the highest
one (i.e. always a predetermined window number):

$ screen -X screen $(($(screen -Q windows | sed -e 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/')+1)) mc

(needs bash or zsh for $((expression)) to work)

Or separated to reuse the window number elsewhere:

$ windownumber=$(($(screen -Q windows | sed -e 's/^.*[^0-9]\([0-9][0-9]*\)[^0-9]*\$[^$]*$/\1/')+1))
$ echo Window will be created with number $windownumber
$ screen -X screen $windownumber mc

HTH.

		Kind regards, Axel
-- 
/~\  Plain Text Ribbon Campaign                   | Axel Beckert
\ /  Say No to HTML in E-Mail and News            | [email protected]  (Mail)
 X   See http://www.nonhtmlmail.org/campaign.html | [email protected] (Mail+Jabber)
/ \  I love long mails: http://email.is-not-s.ms/ | http://abe.noone.org/ (Web)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.