Created
May 24, 2020 05:23
-
-
Save nick3499/78b449830b29e706ecb14a461336fc8f to your computer and use it in GitHub Desktop.
Set background image and display mode in gsettings: subprocess.run(), click
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/python3 | |
'''`set_bg_img` module contains `set_img()` method which sets image URI and display mode. | |
$ python3 set_bg_img.py''' | |
from subprocess import run | |
from click import command | |
from click import option | |
from click import Choice | |
@command() # command options | |
@option('--img', prompt='Image file') # image URI option | |
@option('--mode', type=Choice(['wallpaper', 'centered', 'scaled', 'stretched', | |
'zoom', 'spanned']), prompt='Display mode') # display mode option | |
def set_img(img, mode): | |
'''Set wallpaper image URI and display mode.''' | |
run(['gsettings', 'set', 'org.gnome.desktop.background', | |
'picture-options', mode], check=True) # set display mode | |
run(['gsettings', 'set', 'org.gnome.desktop.background', | |
'picture-uri', f'file:///home/foo/Pictures/{img}'], check=True) # set image URI | |
if __name__ == '__main__': | |
set_img() # if standalone |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
User prompted for image file URI and display mode: