Ubuntu – Cannot set display options inside a systemd service

systemdxorg

I have the following systemd service I wish to run. The purpose of the script is to fix the display size. I am using systemd because I want to adjust the size before login for .xsession to be called.

cat /etc/systemd/system/fix-display-size.service
[Unit]
Description=Fixes the display size

[Service]
ExecStart=/usr/bin/xrandr --output eDP-1 --scale 0.66x0.66
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

When manually starting this service I have the following output

‚óŹ fix-display-size.service - Fixes the display size
   Loaded: loaded (/etc/systemd/system/fix-display-size.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2020-02-07 22:30:33 EST; 5min ago
  Process: 2838 ExecStart=/usr/bin/xrandr --output eDP-1 --scale 0.66x0.66 (code=exited, status=1/FAILURE)
 Main PID: 2838 (code=exited, status=1/FAILURE)

Feb 07 22:30:33 nathaniels-thinkpad systemd[1]: Starting Fixes the display size...
Feb 07 22:30:33 nathaniels-thinkpad xrandr[2838]: Can't open display
Feb 07 22:30:33 nathaniels-thinkpad systemd[1]: fix-display-size.service: Main process exited, code=exited, status=1/FAILURE
Feb 07 22:30:33 nathaniels-thinkpad systemd[1]: fix-display-size.service: Failed with result 'exit-code'.
Feb 07 22:30:33 nathaniels-thinkpad systemd[1]: Failed to start Fixes the display size.

What can I do?

Related Question