Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python Script to update the XML for Linux Mint Background Slideshow
#!/usr/bin/env python
import os,sys,re
from lxml import etree as ET
folders = sys.argv[1:]
if len(folders) == 0:
sys.stderr.write("No folders given\n")
files = []
for folder in folders:
for basepath,_,newfiles in os.walk(folder):
files.extend(os.path.abspath(os.path.join(basepath, f)) for f in newfiles)
root = ET.Element('wallpapers')
for f in files:
e_e = ET.SubElement(root,'wallpaper',{'deleted': 'false'})
ET.SubElement(e_e,'filename').text = f
ET.SubElement(e_e,'title').text = re.match(".+/(.+)/.+$",f).group(1)
ET.SubElement(e_e,'author').text = os.environ['USER']
sys.stdout.write(ET.tostring(root, encoding="UTF-8", pretty_print=False, xml_declaration=True, doctype='<!DOCTYPE wallpapers SYSTEM "cinnamon-wp-list.dtd">', with_tail=False))
python ~/Documents/Pictures/Screenshots/ | sudo tee /usr/share/cinnamon-background-properties/screenshots.xml | xmllint --format -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.