Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active April 5, 2021 15:30
Show Gist options
  • Save nick3499/9e605fd061c460f94b1330426d92d104 to your computer and use it in GitHub Desktop.
Save nick3499/9e605fd061c460f94b1330426d92d104 to your computer and use it in GitHub Desktop.
Desktop Background Set: GNOME desktop background settings: subprocess.run(), os.listdir(), datetime, gsettings
#!/usr/bin/python3
'''Gnome desktop background settings.'''
from subprocess import run
from os import listdir
from datetime import datetime
WALLPAPERS = listdir('/home/foo/Pictures/Wallpapers')
D = {}
for num, file_name in enumerate(WALLPAPERS):
D[num] = f'/home/foo/Pictures/Wallpapers/{file_name}'
if datetime.now().isocalendar()[1] % 2 == 0:
WKDAY = D[datetime.now().weekday()]
else:
WKDAY = D[datetime.now().weekday() + 7]
run(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-options',
'"wallpaper"'], check=True)
run(['gsettings', 'set', 'org.gnome.desktop.background', 'picture-uri',
f'file://{WKDAY}'], check=True)
@nick3499
Copy link
Author

nick3499 commented Apr 5, 2021

WALLPAPERS lists 14 images for desktop wallpaper in tile mode. So, depending on whether the week number is even or odd will determine which half of the /home/foo/Pictures/Wallpapers directory the current background scheme will come from. Notice how 7 will be added to the weekday value stored in WKDAY if the week number value is odd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment