Skip to content

Instantly share code, notes, and snippets.

@nick3499
Last active March 13, 2020 18:10
Show Gist options
  • Save nick3499/1ee80eaa38ee97b9b8737c5eed6cef38 to your computer and use it in GitHub Desktop.
Save nick3499/1ee80eaa38ee97b9b8737c5eed6cef38 to your computer and use it in GitHub Desktop.
SciFi Wallpaper: Python3: Set desktop wallpaper image in Bash CLI; center it; tile it: os.listdir(), datetime.date(), subprocess.run(), click
#! /bin/python3
'''`scifi_wallpaper` module contains methods for setting background image.
Along with the display mode. Help: $ python3 scifi_wallpaper.py
opensource.org/licenses/MIT'''
from os import listdir
from datetime import date
from subprocess import run
import click
SET_DESK_BG = ['gsettings', 'set', 'org.gnome.desktop.background'] # args 1
@click.group(chain=True) # group the methods
def scifi_wallpaper():
'''scifi_wallpaper group method.'''
@scifi_wallpaper.command() # scifi-wallpaper group
def setimg():
'''Set desktop wallpaper image of the day.'''
list_imgs = listdir('/home/foo/scripts/scifi_wallpaper/img/') # img dir
list_imgs.sort() # sort filenames d01 thru d31
img_uri_args = ['picture-uri',
'file:///home/foo/scripts/scifi_wallpaper/img/' +
list_imgs[date.today().day - 1]] # args 2
run(SET_DESK_BG + img_uri_args, check=True) # run cli args
print(f'wallpaper img: \x1b[1;34m{list_imgs[date.today().day - 1]}\x1b[0m')
@scifi_wallpaper.command() # scifi-wallpaper group
def center():
'''Centered mode for desktop wallpaper image.'''
args_center = ['picture-options', 'centered'] # args 2
run(SET_DESK_BG + args_center, check=True) # run cli args
@scifi_wallpaper.command() # scifi-wallpaper group
def tile():
'''Tile mode for desktop wallpaper image.'''
args_tile = ['picture-options', 'wallpaper'] # args 2
run(SET_DESK_BG + args_tile, check=True) # run cli args
if __name__ == '__main__':
scifi_wallpaper() # if standalone
@nick3499
Copy link
Author

nick3499 commented Mar 13, 2020

The /img directory needs to contain at least 31 images for a 31-day month. Set new image after midnight.

help: $ python3 scifi_wallpaper.py
set image: $ python3 scifi_wallpaper.py setimg
center image: $ python3 scifi_wallpaper.py center
tile image: $ python3 scifi_wallpaper.py tile

Copyright © 2020 nick3499

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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