Unable to take sddm login screenshot

Great, got it working, these are the steps:

  1. In tty1 logout from Plasma sessions, so sddm-greeter is there.
  2. Switch to tty2 with CONTROL+ALT+F2 and login as root there, then run there sudo -i
  3. Run the script capture-sddm.sh in tty2
  4. Switch quickly to tty1 with CONTROL+ALT+F1 and wait 20 seconds to take screenshot
  5. Now the screenshot is in /root/ folder

This is the script capture-sddm.sh to be run as root:

TMPXAUTHORITY=$(ls /var/run/sddm/*)
sleep 15
DISPLAY=:0 XAUTHORITY=$TMPXAUTHORITY xwd -root > /root/greeter.xwd
convert /root/greeter.xwd /root/greeter.png
rm /root/greeter.xwd