Advertisement
Guest User

change_bg

a guest
Jan 17th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.82 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use File::Basename;
  5.  
  6. ### Whoever takes this:
  7. # If this is being run by cron, be sure to set dbus and display settings.
  8. # I just saved you research time.
  9.  
  10. my $directory = '/path/to/wallpapers';
  11. my @walls;
  12.  
  13. my $current_wall = `gsettings get org.cinnamon.desktop.background picture-uri`;
  14. chomp $current_wall;
  15. $current_wall =~ s/\'//g;
  16. $current_wall = basename($current_wall);
  17.  
  18. opendir (DIR, $directory) or die $!;
  19.  
  20. while(my $file = readdir(DIR)){
  21.     next if($file =~ m/^\./); #ignore . & ..
  22.     next if($file !~ m/\.(png|jpe?g)/);
  23.     next if($file eq $current_wall);
  24.     push @walls, $file;
  25. }
  26. my $new_wall_path = "'" . "file://" . $directory . $walls[int(rand(scalar(@walls)))] . "'";
  27.  
  28. `gsettings set org.gnome.desktop.background picture-uri $new_wall_path`
  29. #print $new_wall_path;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement