GUI to Change Background Arctica Greeter (Login Screen) on Ubuntu-MATE 22.04

A GUI to change the login-screen background.
( bash script, using zenity )

#!/bin/bash

mybg="/usr/share/backgrounds/mybackground"
schemadir="/usr/share/glib-2.0/schemas"
configfile="$schemadir/30_ubuntu-mate.gschema.override"

tmpfile="$XDG_RUNTIME_DIR/wallpaper$$"
trap "rm $tmpfile &>/dev/null" INT TERM EXIT

if ! grep "background='$mybg'" "$configfile" &>/dev/null
then
	pkexec sed -i "s|background=.*|background='$mybg'|g" "$configfile"
	pkexec glib-compile-schemas "$schemadir/."
fi

eom "$mybg" &

sleep 1
cp "$(zenity --title LoginBackgroundSelector --file-selection )" "$tmpfile" || exit
pkexec cp "$tmpfile" "$mybg"

eom "$mybg"

It works perfectly but I am not completely satisfied with my use of 'pkexec' here. Any suggestions are welcome.

2 Likes

Ah zenity... I haven't run zenity a loooong time.

You can use sudo and zenity to ask for password.

zenity --password | sudo -S "command"

-S read from stdin

In a script something like this:

if [[ "$EUID" = 0 ]]; then
    echo "already root"
else
    sudo -k # make sure to ask for password on next sudo
    if zenity --password | sudo -S true; then
        echo "correct password"
    else
        echo "wrong password"
        exit 1
    fi
fi
# Do your sudo stuff here. Password will not be asked again due to caching.
sudo sed -i "s|background=.*|background='$mybg'|g" "$configfile"
sudo glib-compile-schemas "$schemadir/."

sudo -k # make sure to ask for password on next sudo

Also have a look at this in the manual

man sudo
.......
-E, --preserve-env
Indicates to the security policy that the user wishes to pre‐
serve their existing environment variables. The security
policy may return an error if the user does not have permis‐
sion to preserve the environment.

3 Likes

Marvellous! Thanks ! Oh yes, that was exactly what I needed, you're awesome :smiley:

EDIT: improved code

#!/bin/bash

exec &>/dev/null
source "$HOME/.config/user-dirs.dirs"

text1="Login Background Changer"
text2="Select Background for Login"
mybg="/usr/share/backgrounds/mybackground"
schemadir="/usr/share/glib-2.0/schemas"
configfile="$schemadir/30_ubuntu-mate.gschema.override"

tmpfile="$XDG_RUNTIME_DIR/delete_me_$$"
cleanup()
{
	rm $tmpfile
	sudo -k
}
trap "cleanup" INT TERM EXIT

zenity --title="$text1" --password | sudo -S true || exit

if ! grep "background='$mybg'" "$configfile"
then
	sudo sed -i "s|background=.*|background='$mybg'|g" "$configfile"
	sudo glib-compile-schemas "$schemadir/."
fi

eom "$mybg" &

sleep 1
cp "$(zenity --title="$text2" --file-selection --filename="$XDG_PICTURES_DIR/*")" "$tmpfile" || exit
sudo cp "$tmpfile" "$mybg"

eom "$mybg"

P.S.:
b.t.w. are you the same misko that composed my favourite laptopbackground ?
(i've gratefully been using this for years now) :slight_smile:

3 Likes

Oh, I'm famous now, ha, ha.
Such a good surprise today, I'm so glad you like the background.
My sister also has it on laptop for years.
Other people told me the kids usually ask why is the fox sleeping. :slightly_smiling_face:

1 Like

Oh, before I forget:
At anyone following this thread, the best solution (much better than my hack) is to revert from arctica-greeter to the old tried en tested (and working) slick-greeter.

1 Like

Thanks tkn for a great script.

I learned some new techniques from the script as well.

1 Like

An easier way...Remove arctica greeter...install slick greeter...install lightdm settings...then go to system/admin and open Login Window app and change background to whatever you like!

3 Likes

Welcome @garmich50 to the community!

Just tried on Ubuntu MATE v22.10.
It works.
I saved your code into a file with nano and ran with source command. Named "MATE-Background-Changer" :grin:
I didn't give the file any suffix. Isn't it better to have a .sh suffix?
By the way, it doesn't run through file explorer - caja by the time - I could only run it through terminal by source or .

Well it's a few steps longer right?
B.T.W, I thought MATE is already using lightdm?
Isn't it?

Technically it doesn't matter at all, but as a reminder for yourself that a file is a script it is absolutely helpful.

You will need to make the file executable by means of caja (properties) or the command chmod a+x

By the way, although this script of mine does work for anyone who wants to keep 'arctica-greeter', it might be better to replace the lightdm-greeter 'arctica' for 'slickgreeter' which will give you the official 'loginscreen' customizing options.
This link shows you how to do that (including settings):
Replace arctica-greeter back to slick-greeter on 20.10 for better compatibilty with other desktop environments

2 Likes

Yep, Thank you!

But I'm so curious!
Just in case, if anyone has some free time to answer,(:pray:) I'm so curious why it's installed by default?
If slick-greeter is more useful and more compatible with other desktops, then why arctica-greeter is installed by default in Ubuntu-MATE? Is it default with Gnome and/or Ubuntu itself? Is it more compatible with MATE except not having the option to change login screen? Or since slick-greeter has some bugs or any problems so we prefer artica to be the default?

Sorry if I'm noob

2 Likes

That is absolutely a very good and very valid question.
To be honest, I don't know :man_shrugging:
I am also a bit curious about that.

The desktop team might have had its reasons.
Maybe @franksmcb or @vkareh know on which technical merits this decision was taken.

2 Likes

The decision to switch to arctica-greeter was made by Wimpy along with the switch to Ayatana Indicators

His explanation for this is in the 22.10 Release Notes

@Norbert_X's how-to posting is still a solid work-around. Replace arctica-greeter back to slick-greeter

4 Likes

To cite the part about Arctica greeter:

  • We’ve switched from Slick Greeter to Arctica Greeter (both forks of Unity Greeter)
    • Arctica Greeter integrates completely with Ayatana Indicators; so there is now a consistent Indicator experience in the greeter and desktop environment.
3 Likes

It also says at first:

Ubuntu MATE 20.10 is our first release to feature Ayatana Indicators and as such there are a couple of drawbacks; there is no messages indicator and no graphical tool to configure the display manager greeter (login window) :disappointed:

Both will return in a future release and the greeter can be configured using dconf-editor in the meantime.

Seems that I already can configure Arctica Greeter after installing dconf-editor, Does anyone have any experience with it?

Edit: I have installed it and you easily can change your logo or background with it, and many others.