How to run a script BEFORE login?

I have a script that I run on login to fix the resolution of my monitor, how can I run it at the sddm?

You cannot run it from within SDDM, but there are various other ways of doing what you want to do. However, the exact method to use will depend upon a number of things… :arrow_down:

  1. What kind of script is it and what’s in it?

  2. Are you using x.org or wayland?

  3. How do you normally execute the script after you’ve logged in, and does it work then?

1- ManjaroMonitor.sh is the name, and these are the contents:

#!/bin/bash
MODE=$(optimus-manager --print-mode | cut -d " " -f 5)
CVT=$(cvt 1920 1080 | tail -1 | cut -d ' ' -f2-)
mName=$(echo $CVT | cut -d ' ' -f1)
xrandr --newmode $CVT

if [[ $MODE == "nvidia" ]]
then
	xrandr --addmode DP-1-1 "$mName"
    xrandr --output eDP-1-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1-1 --off --output DP-1-1 --mode $mName --pos 1366x0 --rotate normal	
else 
	xrandr --addmode DP-1 "$mName"
    xrandr --output eDP-1 --primary --mode 1366x768 --pos 0x312 --rotate normal --output HDMI-1 --off --output DP-1 --mode $mName --pos 1366x0 --rotate normal
fi

2- I think I’m using x.org, but I’m not sure.
3- I added it to the Autostart in the plasma settings and it works fine.

Yes, you are, because xrandr doesn’t work with wayland. :stuck_out_tongue:

Adding it there was going to be one of my suggestions. But if it works and it’s automatically started from there, then why do you need it to run before login?

Because the login screen looks better a 1080p rather than a mirrored 720p :grin:.
Also, the screen black out during the splash screen when running the script, which doesn’t look nice.

Well, what you could try ─ note: untested ─ is add the script to /etc/X11/xinit/xinitrc.d/. Make sure that it’s owned root:root, that it has execute permission, and that it has a name that starts with a two-digit number ─ which will determine its order of execution ─ and that ends in .sh. For instance, something like 50-monitor_settings.sh.

:crossed_fingers:

Is there a risk?

Only that it may not work. But then it’s trivial to remove it again.

Alright, I’ll try it and update.

That worked, thanks :grin:

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.