txvars – Start X Applications from Long Living Screen Sessions

Do your ‘screen’ sessions last for a week or a month? Do you like to start your X applications from the command line? You might need txvars.

This article requires fluency with command line interface.

Problem

Graphical user interface (GUI) applications fail to start from the command line, when you have run ‘screen’ for a long time.

$ gedit stackhay-web.py
(gedit:7693): EggSMClient-WARNING **: Failed to connect to the session manager: Could not open network socket
** (gedit:7693): WARNING **: Could not connect to session bus

The problem happens only after running screen for an extended period. Closing the screen session and starting a new one usually fixes the problem.

Useful X Applications to Start from Command Line

Running X apps from the command line can save some typing. For example

$ thunar . &
$ nautilus --no-desktop . &
$ gedit foo.py &
$ firefox index.html &

Solution: txvars

Txvars stores session variables from your X desktop session. You can then bring the session variables to your screen session, so that you can start X applications from the command line.

Install

Install the shell script anywhere in your $PATH

$ sudo cp txvars /usr/local/bin/
$ sudo chmod a+x /usr/local/bin/txvars

Usage

In your graphical X desktop session, run txvars. For example in XFCE (Xubuntu), press Alt-F2 and type ‘txvars’. This collects your X session variables.

In your command line ‘screen’ session, bring in the saved session variables

$ source $HOME/.txvars

You can now start graphical user interface (X) commands from your screen session. For example, give the command ‘gedit’ and see that a window opens.

Source Code

# Save X variables for use in screen
# Copyright 2012 Tero Karvinen http://TeroKarvinen.com

# Essential ones are DISPLAY, SESSION_MANAGER and DBUS_SESSION_BUS_ADDRESS 

set|grep -P '^(DISPLAY|SESSION_MANAGER|DBUS_SESSION_BUS_ADDRESS|SSH_AGENT_PID|SSH_AUTH_SOCK)=' \
        |xargs -n1 echo "export"   > $HOME/.txvars

# Fix for bug:
# "Cannot open display:"        # DISPLAY
# "Warning: Tried to connect to session manager, Could not open network socket" # SESSION_MANAGER
# "Could not connect to session bus"    # DBUS_SESSION_BUS_ADDRESS

# See also:
# http://alan.lamielle.net/2009/03/09/environment-variables-and-gnu-screen
# http://samrowe.com/wordpress/ssh-agent-and-gnu-screen/
# http://lists.fedoraproject.org/pipermail/devel/2007-October/111589.html

Administrivia

Tested on Ubuntu 12.04 LTS.

Edits: typos

Update 2015: Works on Xubuntu 14.04 LTS amd64, too.

Posted in Uncategorized | Tagged , , , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Picks

  • Boxing Clock for AndroidOcton8 Diving T-ShirtsShaking Tower Panda Android GameLearn Chinese with Android
  • Student projects