31 lines
878 B
Python
31 lines
878 B
Python
|
import pathlib
|
||
|
import random
|
||
|
|
||
|
import gi
|
||
|
|
||
|
gi.require_version("Gtk", "4.0")
|
||
|
from gi.repository import Gio, Gtk
|
||
|
|
||
|
import click
|
||
|
|
||
|
|
||
|
@click.command()
|
||
|
@click.argument(
|
||
|
"backgrounds_directory", type=click.Path(exists=True, path_type=pathlib.Path)
|
||
|
)
|
||
|
def choose_random_background(backgrounds_directory: pathlib.Path):
|
||
|
background = random.choice(
|
||
|
[
|
||
|
path.expanduser().resolve().as_uri()
|
||
|
for path in backgrounds_directory.iterdir()
|
||
|
if path.suffix.lower() in [".jpg", ".jpeg", ".png"]
|
||
|
]
|
||
|
)
|
||
|
print(background)
|
||
|
settings = Gio.Settings.new("org.gnome.desktop.background")
|
||
|
if settings.get_string("picture-uri") != background:
|
||
|
settings.set_string("picture-uri", background)
|
||
|
if settings.get_string("picture-uri-dark") != background:
|
||
|
settings.set_string("picture-uri-dark", background)
|
||
|
settings.apply()
|