Skip to content

Instantly share code, notes, and snippets.

@stevelippert
Created February 11, 2014 14:17
Show Gist options
  • Select an option

  • Save stevelippert/8935608 to your computer and use it in GitHub Desktop.

Select an option

Save stevelippert/8935608 to your computer and use it in GitHub Desktop.
Bing Wallpaper Downloader
use strict;
use warnings;
use URI;
use LWP::Simple;
use File::Spec;
use File::Copy;
use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
use Data::Dumper;
use 5.14.0;
my $debug = 0;
my $content = get("http://www.bing.com");
die "Error contacting Bing" unless defined $content;
$content =~ /g_img=\{url:'(.+?)'/;
my $image = $1;
$debug && say "Image: " . $image;
my $uri = URI->new( $image );
$uri->scheme( 'http' );
$uri->host( 'www.bing.com' );
$debug && say $uri;
my( undef, undef, $filename) = File::Spec->splitpath( $image );
my $ultimateTarget = File::Spec->catfile('C:', 'Users', 'steve.lippert', 'AppData', 'Roaming', 'Microsoft', 'Windows', 'Themes', 'TranscodedWallpaper.jpg');
my $target = File::Spec->catfile( 'C:', 'Users', 'steve.lippert', 'Dropbox', 'Photos', 'Wallpapers', 'Bing', $filename );
my $imageDownload = getstore($uri, $target);
copy($target,$ultimateTarget);
my $desktopKey = $Registry->{"HKEY_CURRENT_USER/Control Panel/Desktop//Wallpaper"};
my $desktop = $desktopKey->[0];
$Registry->{"HKEY_CURRENT_USER/Control Panel/Desktop//Wallpaper"} = $desktop;
system "RUNDLL32.EXE user32.dll,UpdatePerUserSystemParameters";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment