Skip to content

Instantly share code, notes, and snippets.

@krishraghuram
Last active October 30, 2020 19:07
Show Gist options
  • Save krishraghuram/5b9d2cfa4e917e0eb343b1d713c5b2b7 to your computer and use it in GitHub Desktop.
Save krishraghuram/5b9d2cfa4e917e0eb343b1d713c5b2b7 to your computer and use it in GitHub Desktop.
import subprocess
import re
command = ['qdbus', 'org.kde.plasmashell', '/PlasmaShell', 'org.kde.PlasmaShell.evaluateScript']
command.append("""
var allDesktops = desktops();
for (i=0;i<allDesktops.length;i++)
{
d = allDesktops[i];
d.wallpaperPlugin = "org.kde.image";
d.currentConfigGroup = Array("Wallpaper", "org.kde.image", "General");
d.writeConfig("Image", "file://%s");
}
""")
proc = subprocess.run(['acpi','-i'], stdout=subprocess.PIPE)
acpi_info = proc.stdout.decode('utf-8')
if re.search('Discharging',acpi_info):
command[-1] = command[-1] % '/home/raghuram/Pictures/discharging.png'
elif re.search('Charging',acpi_info) or re.search('Full',acpi_info):
command[-1] = command[-1] % '/home/raghuram/Pictures/charging.png'
else:
command[-1] = command[-1] % '/home/raghuram/Pictures/shrug.png'
subprocess.run(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment