0

I would like to make a shell script and an Applescript script to fire an X environment command when this environment is active ( through XQuartz for example ). But not just upon starting the X environment ( which is straight forward ).

To achieve this I need the value of the X environment variable:

${DISPLAY}

I thought that an easy method would be to store this value in a ${HOME}/.display file from a ${HOME}/.xinitrc and remove this file on exit ( trap or sequential execution ).

Is there any "good", "experimented", clean and safe method to get this value outside of the X environment?

1 Answer 1

1

There's no one "correct" way of transferring data, such as the contents of that environment variable, from one program to another. There's multiple options with varying levels of complexity, reliability, security, etc.

You can basically do whatever suits you best ranging from very simple to very complex. For example, when you know you have the X display server on the local computer, the enviroment variable just contains the display number and the screen number. You could let the user enter those values themselves, just letting the shell script prompt the user.

A much more complex way would be to setup a SQL database where you can store the value of the environment variable. You could have a program running in the X session that continually updates the data so that you could detect the X session being closed. This would in almost all cases be a terrible approach that is basically overkill.

The middle ground is simple, but not too simple, methods such as having a file with a well-known name where you store the contents. Or you could have a named pipe established where you can receive the contents.

3
  • The word "better" in my question was an error. I know there isn't such a concept. I tried to improve the english of my question thanks to your very complete first answer.
    – athena
    Commented Jun 14, 2022 at 8:22
  • If XQuartz is installed, isn't $DISPLAY always set? it may be a socket, but it's always there. Commented Jun 14, 2022 at 23:12
  • @MarcWilson I think the idea here is to have a program running completely outside the X session (could even be on a different computer), and to be able to transfer the information necessary to connect to that program. You could also be running multiple X servers on the same computer, and need to choose the right one for connecting.
    – jksoegaard
    Commented Jun 14, 2022 at 23:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .