Skip to content

Instantly share code, notes, and snippets.

@ablakely
Last active February 13, 2022 19:52
Show Gist options
  • Save ablakely/1d9b37257d0a508cf63c35a0749d3d23 to your computer and use it in GitHub Desktop.
Save ablakely/1d9b37257d0a508cf63c35a0749d3d23 to your computer and use it in GitHub Desktop.
Wallpaper Rotation Script for Elementary OS
#!/usr/bin/perl -w
# changebg.pl: Wallpaper rotation script for ElementaryOS
#
# Tested on
# ElementaryOS v5.1.2
#
# Written by Aaron Blakely <aaron@ephasic.org>
# Copyright 2020 (C) Ephasic Software
use strict;
use warnings;
my $WPDIR = "~/Documents/Wallpapers";
my $SLEEPTIME = 30; #in seconds
# resolve ~
if ($^O eq "linux") {
my $whoami = `whoami`; chomp $whoami;
$WPDIR =~ s/\~/\/home\/$whoami/;
}
sub getWPList {
my @wallpapers;
opendir(WPS, $WPDIR) or die $!;
while (my $file = readdir(WPS)) {
if ($file =~ /\.png$/ || $file =~ /\.jpg$/) {
print "Found WP: $file\n";
push(@wallpapers, $WPDIR."/".$file);
}
}
closedir(WPS);
return @wallpapers;
}
while (1) {
my @wps = getWPList();
my $newwp = $wps[int(rand($#wps))];
print "Changing background to: $newwp\n";
system "gsettings set org.gnome.desktop.background picture-uri file://$newwp";
print "Sleeping for $SLEEPTIME seconds\n";
sleep($SLEEPTIME);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment