Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xtitle: can't open display. #25

Open
aidiss opened this issue May 31, 2020 · 2 comments
Open

xtitle: can't open display. #25

aidiss opened this issue May 31, 2020 · 2 comments

Comments

@aidiss
Copy link

aidiss commented May 31, 2020

I tried to create a systemctl service that would dump title every few seconds

Hre is the service file:

[Unit]
Description=ServiceTest

[Service]
ExecStart=xtitle >> ~/dump

[Install]
WantedBy=default.target
$ systemctl --user status monitor
● monitor.service - ServiceTest
     Loaded: loaded (/home/ads/.config/systemd/user/monitor.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Sun 2020-05-31 11:07:24 EEST; 1s ago
TriggeredBy: ● monitor.timer
    Process: 7434 ExecStart=/usr/bin/xtitle >> ~/dump (code=exited, status=1/FAILURE)
   Main PID: 7434 (code=exited, status=1/FAILURE)

May 31 11:07:24 sun systemd[1040]: Started ServiceTest.
**May 31 11:07:24 sun xtitle[7434]: xtitle: can't open display.**
May 31 11:07:24 sun systemd[1040]: monitor.service: Main process exited, code=exited, status=1/FAILURE
May 31 11:07:24 sun systemd[1040]: monitor.service: Failed with result 'exit-code'.

@zjeffer
Copy link

zjeffer commented Oct 25, 2021

You have to specify the X display name, like so:

In a shell script:

#!/bin/sh
DISPLAY=:0 xtitle >> ~/dump

In your service file:

[Service]
ExecStart=/path/to/shellscript.sh

There's probably a way for you to do it in the service file instead of a separate script, but I haven't found it yet.

@SeerLite
Copy link

To set environment variables directly in the service file you can use the env command:

[Service]
ExecStart=/usr/bin/env DISPLAY=:0 /usr/bin/xtitle >> ~/dump

However, the redirection (the >>) won't work as that's part of shell syntax and systemd doesn't understand it. The manual (systemd.service(5)) explains it:

This syntax is inspired by shell syntax, but only the meta-characters and expansions described in the following paragraphs are understood, and the expansion of variables is different. Specifically, redirection using "<", "<<", ">", and ">>", pipes using "|", running programs in the background using "&", and other elements of shell syntax are not supported.

But you can call the shell itself to use that specific feature (in which case you can drop env as sh can set environment variables too):

[Service]
ExecStart=/usr/bin/sh -c 'DISPLAY=:0 xtitle >> ~/dump'

That said, if all you want is to monitor the window title as it changes, systemd is probably the wrong tool for what you are (and OP was at some point) trying. (Unless it's to fork the process to background to allow monitoring it via systemctl in which case it's perfectly valid).

Instead, depending on your environment you can subscribe to the window manager directly and only call xtitle when reported by the window manager. I won't go into details about this as it all depends an what you're trying to accomplish. Still, I hope I gave some useful information ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants