I'm using Ubuntu 18.04.
The above command (and other gsetting command when used with sudo -u <user_name> -H) is/are showing a weird behavior.. (I'm expecting it to set the gsetting of the current user)

  • Firstly, after using the above command from terminal/script, if we try gsettings get the desktop background, it'll show as the picture we set it to previously, but the desktop background is not changed.
  • Second part is, if we log off and log-in (or even, open the background seiings in the settings UI and close it without making any changes) the gsettings get will now display back the normal value, i,e. the current display picture(not the set by us)

Please help me understand this behavior, and what can I do to make it set the gsettings to the current user (using sudo).
Please refer: Trouble with handling sudo
Thanks a loads!

Edit 1:
Just figured out this is happening coz of missing an env variable DBUS_SESSION_DBUS_ADDRESS. When we are using sudo -Hu <user> env > text.txt we get a very limited subset of env varables.. in which the above variable is missing.. From: Background not changing using gsettings from cron

Now, my question boils down to how to add that env variable while I'm setting gsettings through python script! OR is there any other better way of doing it?

  • run sudo -Hu <current_user> env > test.txt, you'll see many environment settings are missing. I guess it's related. – Alvin Liang Dec 3 '19 at 10:31
  • Why do you need sudo to run the command for the current user? Am I missing something? – pomsky Dec 3 '19 at 10:44
  • @pomsky , I understand that things will get easy without sudo.. But, it is a part of flow of scripts, certain set of scripts provides what changes to make in gsettings and at the end of the flow, I'll have to apply the changes to the system... the previous scripts need sudo and I want the applying to gsettings part to go with the flow – frankenstein Dec 3 '19 at 10:52
  • @AlvinLiang , yeah.. just figured out this is happening coz of missing an env variable DBUS_SESSION_DBUS_ADDRESS.. – frankenstein Dec 3 '19 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.