Skip to content

Instantly share code, notes, and snippets.

@codemonkey76
Created June 8, 2023 10:45
Show Gist options
  • Save codemonkey76/ef3aa7fe6a8e5ff01b4b9cc7c0e0d3f6 to your computer and use it in GitHub Desktop.
Save codemonkey76/ef3aa7fe6a8e5ff01b4b9cc7c0e0d3f6 to your computer and use it in GitHub Desktop.
import os
import re
import random
import subprocess
def run_command(cmd):
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True)
return result.stdout.decode('utf-8').strip()
def get_current_bg(output):
match = re.search(r'image: "([^"]+)"', output)
if match:
return match.group(1)
else:
raise ValueError("Failed to extract current background from swww query output")
# Get the current background
query_output = run_command('swww query')
current_bg = get_current_bg(query_output)
# List all files in the backgrounds directory
bg_dir = '/home/shane/.config/HyprV/backgrounds' # replace with your actual directory
all_bgs = os.listdir(bg_dir)
new_bgs = [bg for bg in all_bgs if bg != current_bg]
# If there are no new images, throw an exception
if not new_bgs:
raise ValueError("No more backgrounds found")
# Select a new background at random
new_bg = random.choice(new_bgs)
run_command(f'swww img --transition-type grow --transition-pos top-right --transition-angle 45 {os.path.join(bg_dir, new_bg)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment