Ask Your Question
0

Modify dconf settings of active user from root shell

asked 2014-09-17 15:28:33 -0500

tuxor gravatar image

updated 2014-09-17 15:33:31 -0500

While setting up a script for acpid event handling on FC20.x86_64, I faced the problem of changing dconf settings of the user that is currently logged in and using Gnome (from inside of a script that is run as root).

To read the current state of a user's dconf setting, you simply have to run dconf read or gsettings get with the corresponding su <username> -c ... in front. Using the same method to modify a dconf setting seems to fail in some cases or at least behaves significantly differently from what you would expect.

You can test this yourself:

  1. Activate the a11y-on-screen keyboard in the gnome a11y-settings
  2. Open a gnome-terminal, log in as root via su - and run

    su <username> -c "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false"
    
  3. Check that the value has really changed, e.g. by running as your user

    gsettings get org.gnome.desktop.a11y.applications screen-keyboard-enabled
    
  4. Note that the on-screen-keyboard still appears, because Gnome doesn't seem to have noticed the change.

  5. Try the same, but log in as root in a tty - this time modifying dconf settings won't work at all!

  6. Try to simulate the user's environment by setting variables like $DISPLAY, $XAUTHORITY or $DBUS_SESSION_BUS_ADDRESS or by using su - <username> -c "...". Or try using directly the dconf command instead of gsettings. It will exhibit similar behaviour and still won't work as expected.

If you're feeling adventurous, try this inside of an acpid event handler script in /etc/acpi/actions/

My question: Is it at all possible to change a user's dconf settings (successfully) from inside a root shell?

edit retag flag offensive close merge delete

Comments

I don't think you need to change gsettings value as a root user. For a normal user you can change this value as

gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled false
pnemade gravatar imagepnemade ( 2014-09-17 19:27:18 -0500 )edit

Are you restarting the user's session after making the change? They might not be picked up immediately.

randomuser gravatar imagerandomuser ( 2014-09-17 21:14:37 -0500 )edit

It works for me, logged in into my account, if I do: su german -c "gsettings set org.gnome.desktop.a11y.applications screen-keyboard-enabled true" (where german is my user name). It doesn't work if I use su - german -c "...".

skytux gravatar imageskytux ( 2014-09-17 23:14:20 -0500 )edit

looks like when I edited my comment it failed to get saved. for dnf use following command "dconf write /org/gnome/desktop/a11y/applications/screen-keyboard-enabled false"

pnemade gravatar imagepnemade ( 2014-09-18 00:07:29 -0500 )edit

@pnemade and @randomuser: As I said, I want to execute this in a acpid event handler script, which is always run as root. And so your suggestions don't really help. @skytux: Try it from a tty please.

tuxor gravatar imagetuxor ( 2014-09-23 04:54:39 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-04-18 07:36:36 -0500

This may help My scenario: I wanted root to update the screen background to indicate the status of a root process. I tried using gsettings set org.gnome.desktop.background picture-uri 'file:///usr/share/backgrounds/gnome/pic1.jpg' I tried using dconf /org/gnome/desktop/background/picture-uri 'file:///usr/share/desktop-base/spacefun-theme/wallpaper/gnome-background.xml" The results where the configuration changed but no change would activate any setting monitor, and thus no change in the screen I was using. I presume a log out and in would have the updated background. Not useful in my usage scenario.

I only got a hint with the following error when I tried sudo as a normal user error: Cannot autolaunch D-Bus without X11 $DISPLAY

The solution that worked for me was to ssh -X in as the user and then both mechanism worked correctly updating the screen correctly

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-09-17 15:28:33 -0500

Seen: 3,682 times

Last updated: Sep 17 '14