Skip to main content
added a summary
Source Link
Georgi Stoyanov
  • 860
  • 5
  • 20
  • 41

[UPDATE]: I have tried both proposed solutions but they were both not working. First I have tried the solution of Fiximan. I have created the monitor-check.service in /etc/systemd/system and tried to execute the /bin/bash /home/user/monitor-check.service and it successfully changed the laptop resolution to 3440x1440. Then I have tried to execute: sudo systemctl start monitor-check.sh and this is the status message:

monitor-check.service - Service to check for external monitors during boot.
   Loaded: loaded (/etc/systemd/system/monitor-check.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-07-09 19:27:17 CEST; 5s ago
  Process: 4177 ExecStart=/bin/bash /home/user/Documents/scripts/display_setup.sh (code=exited, status=1/FAILURE)
 Main PID: 4177 (code=exited, status=1/FAILURE)

Jul 09 19:27:17 acer systemd[1]: Started Service to check for external monitors during boot..
Jul 09 19:27:17 acer bash[4177]: Can't open display
Jul 09 19:27:17 acer bash[4177]: Can't open display
Jul 09 19:27:17 acer systemd[1]: monitor-check.service: Main process exited, code=exited, status=1/FAILURE
Jul 09 19:27:17 acer systemd[1]: monitor-check.service: Failed with result 'exit-code'.

I have tried to add the environment variable to the Xauthority by adding: Environment=XAUTHORITY=/run/user/1000/gdm/Xauthority to the Service section but it didn't help.

I have also tried the proposed solution by Praveen but it didn't work either. In fact, I have added my script to /etc/profile.d directory but it didn't execute the script so my resolution was still the old one.

In conclusion, the only two solutions which worked was to add the script to the ~/.profile or to add it manually to the Startup Applications but both solutions change the resolution and switches off the internal laptop display after logon to the system.

[UPDATE]: I have tried both proposed solutions but they were both not working. First I have tried the solution of Fiximan. I have created the monitor-check.service in /etc/systemd/system and tried to execute the /bin/bash /home/user/monitor-check.service and it successfully changed the laptop resolution to 3440x1440. Then I have tried to execute: sudo systemctl start monitor-check.sh and this is the status message:

monitor-check.service - Service to check for external monitors during boot.
   Loaded: loaded (/etc/systemd/system/monitor-check.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2019-07-09 19:27:17 CEST; 5s ago
  Process: 4177 ExecStart=/bin/bash /home/user/Documents/scripts/display_setup.sh (code=exited, status=1/FAILURE)
 Main PID: 4177 (code=exited, status=1/FAILURE)

Jul 09 19:27:17 acer systemd[1]: Started Service to check for external monitors during boot..
Jul 09 19:27:17 acer bash[4177]: Can't open display
Jul 09 19:27:17 acer bash[4177]: Can't open display
Jul 09 19:27:17 acer systemd[1]: monitor-check.service: Main process exited, code=exited, status=1/FAILURE
Jul 09 19:27:17 acer systemd[1]: monitor-check.service: Failed with result 'exit-code'.

I have tried to add the environment variable to the Xauthority by adding: Environment=XAUTHORITY=/run/user/1000/gdm/Xauthority to the Service section but it didn't help.

I have also tried the proposed solution by Praveen but it didn't work either. In fact, I have added my script to /etc/profile.d directory but it didn't execute the script so my resolution was still the old one.

In conclusion, the only two solutions which worked was to add the script to the ~/.profile or to add it manually to the Startup Applications but both solutions change the resolution and switches off the internal laptop display after logon to the system.

Source Link
Georgi Stoyanov
  • 860
  • 5
  • 20
  • 41

Execute a script before login screen

I am trying to run a script before the login screen in Ubuntu 19.04. The script checks if there is an external monitor connected to my notebook and if there is one it changes the resolution to 3440x1440@44 and switches off the internal laptop display. This is my script:

#!/bin/bash

EXTERNAL_OUTPUT="HDMI-1-1"
INTERNAL_OUTPUT="eDP-1-1"

xrandr |grep $EXTERNAL_OUTPUT | grep " connected "
if [ $? -eq 0 ]; then
    xrandr --output $INTERNAL_OUTPUT --off
    xrandr --newmode "3440x1440_44.00"  299.75  3440 3664 4024 4608  1440 1443 1453 1479 -hsync +vsync
    xrandr --addmode HDMI-1-1 "3440x1440_44.00"
    xrandr --output HDMI-1-1 --mode "3440x1440_44.00"
else
    xrandr --output $INTERNAL_OUTPUT --auto --output $EXTERNAL_OUTPUT --off
fi

I have tried to put this script both in ~/.profile and also in the Startup Applications but my GDM login is still present only on my notebook screen. I want this script to be executed even before that time so that I am not present with a black picture upon starting my computer.