I wrote the following script to enable certain GNOME shell extensions. I noticed that this script will return different behaviours when it is executed as "sudo" as compared to "ordinary user".
As Ordinary User: From terminal, after issuing python3.6 scriptname.py
, this script will make the necessary settings changes, the effects will be visible, and the changes will be registered in the "dconf Editor", i.e. its /org/gnome/shell/enabled-extensions tab will contain the values of GS_ENABLED_EXTENSIONS. When I manually re-issued the command Alt+F2+r+Return, the enabled extensions remains in effect.
As sudo: First, I used the dconf Editor to reset /org/gnome/shell/enabled-extensions to it's original value. Next, from the terminal, after issuing sudo python3.6 scriptname.py
, the script's setting will take effect and the setting changes will be visible. However, when I re-opened the dconf Editor, i.e. /org/gnome/shell/enabled-extensions, I noticed the values of GS_ENABLED_EXTENSIONS will not appear there. In fact, it's original value still appears. Now, when I manually re-issued the command Alt+F2+r+Return, the enabled extensions settings by the script will be visually lost, and visually the GNOME shell will show the extensions in the dconf Editor, i.e. it's original values.
Question: Why does the gsettings set
command behave differently when it is executed as sudo
as compared to an "ordinary user"? Is there a way for sudo to return the same behavior as an ordinary user?
#!/usr/bin/python3.6
# -*- coding: utf-8 -*-
import sys
import ast
import time
from subprocess import run, PIPE
INSTALLED_GSEXTENSIONS = ['user-theme@gnome-shell-extensions.gcampax.github.com',
'workspace-indicator@gnome-shell-extensions.gcampax.github.com']
def set_gs_enabled_extensions():
global GS_ENABLED_EXTENSIONS, CMD
print( '\nEnabling GNOME shell extensions...' )
#Commands
get_enabled_extensions = [ 'gsettings', 'get', 'org.gnome.shell', 'enabled-extensions' ]
set_enabled_extensions = [ 'gsettings', 'set', 'org.gnome.shell', 'enabled-extensions' ]
#Get existing GS enabled extensions (if any).
enabled_extensions = run( get_enabled_extensions, stdout=PIPE ).stdout.decode().rstrip()
GS_ENABLED_EXTENSIONS = set( ast.literal_eval( enabled_extensions ) )
#Enable existing and installed GS extensions.
GS_ENABLED_EXTENSIONS.update( INSTALLED_GSEXTENSIONS )
begin=' '.join( set_enabled_extensions )
CMD=f'{begin} "{[*GS_ENABLED_EXTENSIONS,]}"'
print( '\nCMD=', CMD )
run( CMD , shell=True, stdout=sys.stdout )
print( 'Enabling GNOME shell extensions... Done' )
def restart_gnome_shell():
print( '\nRestarting GNOME shell ...' )
cmd = 'xdotool key "Alt+F2+r" && sleep 0.5 && xdotool key "Return"'
run( cmd, shell=True, stdout=sys.stdout )
print( '\Restarting GNOME shell ... Done.' )
def main():
set_gs_enabled_extensions()
restart_gnome_shell()
if __name__ == "__main__":
main()