-1

Is there a way to connect to the X server from the .sh script? I tried

#!/bin/bash
export DISPLAY=:1
BASEDIR=`dirname "${0}"`
cd "$BASEDIR"
python_header.py

but no luck.

Shota
  • 6,910
  • 9
  • 37
  • 67
Jack
  • 725
  • 1
  • 10
  • 27
  • 1
    In which sense is this script trying to "connect" and how does it fail? – tripleee May 01 '15 at 15:19
  • This is the error in the log: No protocol specified Unable to access the X Display, is $DISPLAY set properly? – Jack May 01 '15 at 15:24
  • 1
    But you get that from the Python script then, not from this shell script? Is DISPLAY set to the right value? – tripleee May 01 '15 at 15:26
  • How would I set it to the right value? – Jack May 01 '15 at 15:28
  • You need to find out what the correct value for the display you want to connect to is and use that. – Etan Reisner May 01 '15 at 15:29
  • Could you elaborate please. I don't know how to get the correct value. – Jack May 01 '15 at 15:30
  • 1
    Then why do you believe `DISPLAY=:1` would work? Anyway, see if it’s already set in your current session, and/or just guess that `DISPLAY=:0.0` is probably a better wild guess. – tripleee May 01 '15 at 15:40
  • 2
    please see [this post](http://stackoverflow.com/questions/784404/how-can-i-specify-a-display) if it helps you finding the right value for the display. – Tim Rijavec May 01 '15 at 15:43
  • Where is the script being run? If it's run by a user in an X session, they should already have DISPLAY set to the correct value (and you shouldn't change it). – Charles Duffy May 01 '15 at 15:48
  • If it's being run by something like `cron` (which is outside any X sessions running on the host), then the value you need is very fact-intensive and depends on the security measures in place on your particular system (which may include Xauthority cookies and the like). – Charles Duffy May 01 '15 at 15:48
  • I typed echo $Display in my terminal and it gives me :0, then I added export DISPLAY=:0 to my script the error is the same. No protocol specified Unable to access the X Display, is $DISPLAY set properly? – Jack May 01 '15 at 17:37

1 Answers1

0

Just an update for those who might have the same problem: The following link

http://www.thegeekstuff.com/2010/06/xhost-cannot-open-display/

and then adding this to my code:

     export DISPLAY=:0.0 

solved the problem

Jack
  • 725
  • 1
  • 10
  • 27