OK. Enough chit chat. Lets get down to business. Most of the time you will use screen interactively. You want another screen windows, you press the buttons. But maybe unknown to some, screen is in some sort scriptable. It unfortunately is not straightforward and the very good manual gives only hidden hints. But if you know the edges it’s quite helpful.

This line starts the application. After the application finishes the screen session focuses on the applications window, which means you will be automatically brought to that window. You don’t lose time looking and looking whether the application already finished. In the meantime you can continue work in another window.

You can get the windownumber by pressing C-a w . It’s the number right in front of the name of the screen which is marked by the star. If your windows have distinct names you can also use the name as parameter for the select command!

Wow. You just left the current window and went to the next window. This is the same as pressing C-a n or C-a :next<CR> . Impressive, isn’t it? :)

The first and basic parameter you need to know is -X . With this parameter you can send screen commands to any screen session (for a list of screen commands take a look at the very fine man page for screen). By default it uses the screen session you are currently attached to. So just to test this, start screen , create a second window pressing C-a c . Now enter the following line at the shell prompt:

screen -X -p

We just talked about different windows and their names/numbers. Consider the screen command stuff . It is used to send keystrokes to a window. By default the current window is used as the target. But this command is not very helpful if used interactively like

$ screen -X stuff hello

This way you can write notes to yourself. But if you add the parameter -p to this line you can send those commands to another window in the same screen session. Now this is helpful. You can remote control applications in windows this way. Consider the following example:

Create a screen-window and start e.g. w3m in it to show a webpage which changes over time (w3m is a console web browser like lynx or links). This could be a webpage showing usage statistics or stock information on the net or whatever. For this example we will use a page which shows the current weather for munich:

$ w3m http://www.meteo24.de/wetter/49X7464.html

This will output the current temperature etc. for munich. Unfortunately this display is not updated automatically. You manually have to reload the page. Let’s see how screen can help us.

Give the window a distinct name or just use the number of the screen window. To rename the current window to another name press C-a :title watchit . The current screen window now has the name "watchit". Enter C-a w to check this.

Now comes the interesting part. Go to another window in your screen session. To reload the website in w3m you have to enter R ( Shift-r ). So using the following line we periodically send R to the w3m-window which then reloads the website and updates the display.

$ while true; do screen -p watchit -X stuff R; sleep 5m; done

The sleep -command is used to reload the webpage only once every 5 minutes. You can enter nearly any value here. See man sleep for more information about sleep.