One little problem I’ve been trying to decipher for my own benefit is a script to shut down screen. I usually have five or six applications running in screen, and when I close the machine for shutdown, I manually step through each program, giving it the command to close (and sometimes save).
Since it’s possible to pipe keystrokes through screen to the appropriate application, it seems to follow that a simple five- or six-line series of commands could cleanly save and close everything I usually have running. Technically, the command looks like this:
screen -p elinks -X stuff Q
A shifted Q is a quick shutdown command for elinks, and sending that through screen to the window entitled “elinks” (which is always called “elinks,” because it’s triggered at startup in my .screenrc) causes the application to stop. This will shut down alpine, since the command there is a q, followed by a y to answer yes to the confirmation.
screen -p alpine -X stuff qy
And so forth and so on. htop can close with a q, wyrd with a shifted Q. The problem comes with applications that require function keys as shutdown commands, such as mc‘s F10 close command, or a series of Escape keys for centerim, or hnb which wants a CTRL+Q to quit.
For some reason, using the keystroke sequences in the GNU/Screen user’s manual don’t enter as escaped, instead they spill onto the screen as typed characters, or are ignored since they don’t form an escape sequence. So if I try this, which I think sends an F10 command to Midnight Commander:
screen -p mc -X stuff \033[21~
The console command line in mc shows
033[21~ after the command prompt, as if I had typed those letters directly myself. Chances are I’m feeding it the wrong commands, or there is some other special switch that I need to add to get it to actually send through as a keystroke instead of raw text.
I could probably just use screen’s default kill switch (CTRL+A CTRL+\) to close everything, but I don’t know if I am comfortable with that. Given that these commands are available and work for some cases, I probably just need a nudge to get the whole thing working as imagined.😐